Linux Command Summary two of common operations

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/Weixiaohuai/article/details/90812489

I. Introduction

Then on a blog, summarize some continue to use common Linux commands.

Second, the command Detailed

[A] cat command: the output file or a combination of standard input standard output, used to display the contents of the file.

cat a.txt: view the contents of the file a.txt

cat / etc / profile: View / etc / profile file contents

cat -n / etc / profile: display the line number to view the / etc / profile

cat -n / etc / profile | more: Paged view / etc / profile file contents 

|: Pipe character, filtering means

more: Paging Display

Similar to the function of the instruction command has more cat and less.

more: on page display text

more /etc/profile

less: split-screen display file contents, less the entire contents of the file will not be a one-time loading, but before going to load the show's content as needed, suitable for displaying the contents of large files, high efficiency.

less /etc/profile

 

[B]> and >> instructions

>: Output redirection symbols, a command to redirect the results to other output devices, the contents of the original file will be overwritten.

>>: additional content to a file, do not overwrite the contents of the original file.

ls -l /> c.txt: command ls -l / output redirected to the contents of the c.txt

ls -l / test> c.txt: content output command ls -l / test redirected to c.txt, the visible contents of the foregoing c.txt is overwritten.

ls -l / >> d.txt: command ls -l / output redirected to the contents of the d.txt

ls -l / test >> d.txt: the contents of the output command ls -l / test redirected to d.txt, the content is only visible at the end of the file append, and does not cover.

 

[C] echo: Output content to the console

echo “hello world”:将“hello world”内容输出到控制台

echo $PATH:输出环境变量或者自定义变量

echo “hello” >>  e.txt: 输出内容到e.txt文件中

 

【d】head指令:用于显示文件内容的开头部分内容,默认展示前10行内容,可以通过-n 指定展示前n行内容

head f.txt: 展示f.txt文件的前10行内容

head -3 f.txt:展示f.txt文件的前3行内容

 

【e】tail指令:用于显示文件内容的结尾部分内容,默认展示后10行内容,可以通过-n 指定展示后n行内容

tail g.txt: 展示g.txt文件的后10行内容

tail -3 g.txt:展示g.txt文件的后3行内容

tail -f参数:实时跟踪文件内容的变化情况

tail -f h.txt :

首先在定时任务crond中加入: 每一分钟输出内容到h.txt

然后监控h.txt文件的变化

crontab -e

*/1 * * * * echo "hello" >> /test/h.txt

 tail -f h.txt

 

【f】history: 用于查看执行过的历史指令

History :查看所有执行过的历史命令

history 5 :查看最近5次执行过的历史指令

 

【g】date指令:主要是用于跟时间日期相关的操作

date:显示当前日期

date  "+%Y年%m月%d日 %H时%M分%S秒":显示当前日期的年月日时分秒

 

【h】cal指令:查看日历信息

cal:查看当前日历

cal 2020: 查看2020年日历信息

 

【i】find指令:  从指定目录向下依次递归地遍历各个子目录,将满足条件的文件或者目录展示出来。

find -name xxx: 按文件名称进行搜索

find -user xxx: 按用户进行搜索

find -size xx: 按文件大小进行搜索

 

find /test -name g.txt : 查询/test目录下文件名称为g.txt的文件

find /test -name *.txt:查询/test目录下所有后缀为.txt的文件

find /test -user wsh: 查询/test目录文件所有者为wsh的文件

find / -size +1M :查询根目录/下文件大小大于1M的文件(1M = 1024k)

find / -size 1M: 查询根目录/下文件大小等于1M的文件

find / -size -1M : 查询根目录/下文件大小小于1M的文件

 

【j】grep和管道符|:两个命令大多数情况下都是结合使用。

grep指令:该指令主要是用于过滤的作用 

管道符号 | :将前面一个命令执行后的结果传递给后面的命令

ls -l /test | grep g.txt :将ls -l /test 执行的结果,然后过滤出g.txt文件

ps -ef | grep sshd:查询sshd服务的相关进程。

 

【k】gzip/gunzip:gzip压缩文件或目录、gunzip用于解压缩文件或目录.

gzip a.txt:将a.txt进行gzip压缩

注意:原来的文件在压缩完成之后会变成.gz的压缩文件,原文件不存在。

gunzip a.txt.gz:将a.txt.gz压缩文件进行解压缩

 

【m】tar: 打包指令,压缩后的文件格式为:xxx.tar.gz

tar -zcvf ab.tar.gz a.txt b.txt:将a.txt/b.txt两个文件压缩为同一个压缩文件ab.tar.gz

tar -zcvf mytest.tar.gz /test:将test目录压缩成mytest.tar.gz

tar -zxvf ab.tar.gz:解压缩文件ab.tar.gz

 tar -zxvf /test/ab.tar.gz -C /mytest: 将压缩文件解压到指定目录

注意指定压缩之后的目录必须事先存在,否则会报错,如下:

 

三、总结

This paper describes the date date command, pipe symbol |, grep command, tar, gzip and other compression / decompression commands, these commands will work are often used, it is necessary to master the use of the following commands, Linux CNOOC many easy to use instruction, the next article will continue to sum up these commonly used commands.

Guess you like

Origin blog.csdn.net/Weixiaohuai/article/details/90812489