Linux utility command (2)

The date and time classes

date instructions - Displays the current date
Syntax:
. 1) date (Function Description: display the current time)
2) date +% the Y (Function Description: Shows the current year)
. 3) date +% m (Function Description: The current month)
. 4) date +% d (function description: currently displayed day)
Here Insert Picture Description
dATE command - set date
syntax: date -s string time
Here Insert Picture Description

View Calendar cal instruction command
syntax: cal [options] (Functional Description: without option to display the calendar month)
Case: Displays the current calendar
Here Insert Picture Description

cal + Year: Shows a calendar year
Here Insert Picture Description

Search by category

find instructions
find instructions downwardly from the specified directory recursively traverse their respective subdirectories, to satisfy the condition file or directory is displayed in the terminal.
Syntax: find [search] [options]
Option Description
Here Insert Picture Description

Case 1: by file name: hello.txt file name lookup / home directory according to
Here Insert Picture Description

Case 2: Press Owner: Find / opt directory under the user name for the file to nobody
Here Insert Picture Description
Case 3: Find the entire file more than 20m in linux system (-n + n greater than equal to less than n)
Here Insert Picture Description

locate instructions
locaate instructions may quickly locate the file path. all locate the database file name and path of realization locate system commands using the previously established quickly locate a given file. Locate command without having to traverse the entire file system, the query faster. In order to ensure the accuracy of the results, the administrator must regularly update the locate database.

语法:locate 搜索文件
特别说明
由于 locate 指令基于数据库进行查询,所以第一次运行前,必须使用 updatedb 指令创建 locate 数据库。

案例 1: 请使用 locate 指令快速定位 hello.txt 文件所在目录
Here Insert Picture Description

grep 指令和 管道符号 |
grep 过滤查找 , 管道符,“|”,表示将前一个命令的处理结果输出传递给后面的命令处理。

语法:grep [选项] 查找内容 源文件

常用选项
Here Insert Picture Description
在hello.txt中写入几行数据
Here Insert Picture Description
查找yes所在的行并且不区分大小写
Here Insert Picture Description

压缩和解压类

gzip/gunzip 指令
gzip 用于压缩文件, gunzip 用于解压的

语法:
gzip 文件 (功能描述:压缩文件,只能将文件压缩为*.gz 文件)
gunzip 文 件.gz (功能描述:解压缩文件命令)

案例 1: gzip 压缩, 将 /home 下的 hello.txt 文件进行压缩
Here Insert Picture Description

案例 2: gunzip 压缩, 将 /home 下的 hello.txt.gz 文件进行解压缩
Here Insert Picture Description

细节说明
当我们使用 gzip 对文件进行压缩后,不会保留原来的文件。

zip/unzip 指令
zip 用于压缩文件, unzip 用于解压的,这个在项目打包发布中很有用

语法:
zip [选项] XXX.zip 将要压缩的内容(功能描述:压缩文件和目录的命令)
unzip [选项] XXX.zip (功能描述:解压缩文件)

Common options zip -r: recursive compression, ie compression directory
unzip common option -d <directory>: After you specify the directory where the file is decompressed

Case 1: All files in the / home compressed into mypackage.zip
Here Insert Picture Description
Here Insert Picture Description

Case 2: mypackge.zip extract to opt under / / tmp directory
Here Insert Picture Description

tar command
tar command is packed instruction, after the last file is packaged .tar.gz file.
Syntax:
tar [options] XXX.tar.gz packaged content (functional description: .tar.gz packaged file format catalog, after compression)
Option Description
Here Insert Picture Description

Case 1: compress multiple files, compressed into a.tar.gz /home/a.txt and /home/b.txt
Here Insert Picture Description

Decompression can be deleted before b.txt a.txt and view the results in
Here Insert Picture Description
case 2: / home folder compressed into myhome.tar.gz
Here Insert Picture Description
Here Insert Picture Description
Case 3: myhome.tar.gz extract to / opt / directory
Here Insert Picture Description
specified decompression to that directory, prior to exist in order to succeed, otherwise it will error.

Published 45 original articles · won praise 43 · views 7083

Guess you like

Origin blog.csdn.net/qq_42193790/article/details/104372141