Lesson 5 .linux advanced command

1.find: find qualified file

格式: find    目录名    选项    查找条件

eg:

find /work/001_linux_basic/dira/  -name "test1.txt"

Description:
 A) / Work / 001_linux_basic / DIRA / indicates the path lookup
 b) -name name to indicate to find files
 c) "test1.txt", find the file you specify the name of test1.txt

find /work/001_linux_basic/dira/  -name "*.txt" 

Description: Find the specified file to the following directory so .txt ending, where * is a wildcard.

find /work/001_linux_basic  -name "dira"

Description: Find whether there dira directory specified directory, dira directory name.

There are some advanced uses find, such as finding the last few days (a few hours) within (before) are subject to change file

find /home -mtime -2   // 查找/home目录下两天内有变动的文件   

2.grep: Use the grep command to locate files that meet the criteria string

格式:    grep    [选项]    [查找模式]    [文件名]
grep -rn "字符串" 文件名
/*    r:递归
 *    n:显示目标的行号
 *    字符串:查找的目标;文件名:查找的对象
 *    可加入-w全字匹配
 */

eg:

grep -n "abc" test1.txt   // 在test1.txt中查找字符串abc
grep -rn "abc" *          // 在当前目录递归查找字符串abc

3.file: identify the file type

格式:    file    文件名

eg:

file ~/100ask/     为directory表明这是一个目录

4.which and whereis: Find command or location of the application

格式:    which 命令名/应用程序名

eg:

which gcc 定位到/usr/bin/gcc
whereis  pwd

Under 5.linux commonly used compression command

Single file compression (decompression) using gzip (.gz) and bzip2 (.bz2)
a plurality of files and directories using tar

gzip common options:

-l    列出压缩文件的内容
-k    在压缩或解压时保留输入文件
-d    将压缩文件进行解压缩

a. View

gzip -l 压缩文件名
eg:    gzip -l pwd.1.gz

b. unpack

gzip -kd 压缩文件名
eg:    gzip -kd pwd.1.gz

Note: This compressed file must be in a single file ending in .gz
c compression.

gzip -k 源文件
eg:    gzip -k mypwd.1       // 得到一个.gz结尾的压缩文件

Note: gzip without any options, it will delete the original files after archiving files. It is recommended to use gzip -k

gzip and bzip2 similarities and differences

gzip and bzip2 basic usage exactly the same.
Different:
. A suffix is not the same as gzip (.gz), bzip2 (.bz2)
b.gzip for small files, bzip2 for large files

tar common options

-c    表示创建用来生成文件包
-x    表示提取,从文件包中提取文件
-t    可以查看压缩文件
-z    使用gzip方式进行处理,它与'c'结合表示压缩,与'x'结合表示解压
-j    使用bzip2方式进行处理,它与'c'结合表示压缩,与'x'结合表示解压
-v    详细报告tar处理的信息
-f    表示文件,后面接着一个文件名
-C <指定目录>    解压到指定目录

1.tar pack, gzip compression

a. Compression

tar -czvf    压缩文件名    目录名
eg:tar czvf dira.tar.gz  dira

Note: tar -czvf and tar czvf same effect
b View.

tar tvf    压缩文件名
eg:tar tvf dira.tar.gz

c. unpack

tar xzvf    压缩文件名
tar xzvf    压缩文件名    -C 指定目录
eg:tar xzvf dira.tar.gz        // 解压到当前目录
eg:tar xzvf dira.tar.gz -C /home/book    // 解压到/home/book

2.tar package, bzip2 compression
a. Compression

tar cjvf    压缩文件名    目录名
eg:tar cjvf dira.tar.bz2  dira

b. View

tar tvf    压缩文件名
eg:tar tvf dira.tar.bz2

c. unpack

tar xjvf 压缩文件名
tar xjvf 压缩文件名  -C  指定目录
eg:tar xjvf dira.tar.bz2   解压到当前目录
eg:tar xjvf dira.tar.bz2 -C  /home/book  解压到/home/book

Guess you like

Origin www.cnblogs.com/huangdengtao/p/12077987.html