Linux file search and packaged

A. File search

locate and find Linux is frequently used commands, new to Linux when using these two commands are silly not tell. Now let's compare the difference in the end what two commands.

1.1 locate

locate so that users can specify whether files have a very fast file search system. The method is to build a database of all file names and paths within the system, including, when looking after you just query the database, without actually deep in the file system. In general distribution among the establishment of the database are placed crontab automatically executed.

1.1.1 Command Format:

Locate [选择参数] [样式]

1.1.2 Function:

locate command can quickly find when searching the database file, locate the fuzzy lookup database consists of updatedb to update the program, updatedb by the cron daemon periodically established, locate command is faster than the entire hard disk to search for information by the data in the database search but less strength is locate the file if found only just recently created or changed its name, you may not find in the default value, updatedb will run once a day, can be modified by the crontab to update the set value. ( Etc / crontab )

locate earmarked for qualified search files, it will go to store in a database file and directory names, locate the query file, go to the search /var/lib/mlocate/mlocage.db , look for a model in line with the conditions of the style file or directory record, you can use special characters (such as "*****" or " ? ", etc.) to specify a template styles, such as specifying a template for the kcpa ner *, the locate 'll find all the strings starting to kcpa and ending ner the file or directory, such as the name kcpartner if the directory name for the record kcpa_ner will include all files in the directory, including subdirectories listed.

locate and find instructions to find a file-like functionality, but locate is through the update program in the hard disk of all the files and directories information to build a database index, the execution loacte find the direct index, the query speed will be faster, the general index database It is managed by the operating system, but can also be issued directly force the system to modify the index update database immediately.

1.1.3 Command parameters:

-e   将排除在寻找的范围之外。

-1  如果 是 1.则启动安全模式。在安全模式下,使用者不会看到权限无法看到 的档案。这会始速度减慢,因为 locate 必须至实际的档案系统中取得档案的权限资料。

-f   将特定的档案系统排除在外,例如我们没有到理要把 proc 档案系统中的档案  放在资料库中。

-q  安静模式,不会显示任何错误讯息。

-n 至多显示 n个输出。

-r 使用正规运算式 做寻找的条件。

-o 指定资料库存的名称。

-d 指定资料库的路径

-h 显示辅助讯息

-V 显示程式的版本讯息

1.1.4 Example:

All begin with the sh file search etc directory: Example 1

[root@CentOS7 ~#]locate /etc/sh       
/etc/shadow
/etc/shadow-
/etc/shells
[root@centos7 ~#]locate -r "/etc/\<sh"  # 正则,锚定词首
/etc/shadow
/etc/shadow-
/etc/shells
[root@centos7 ~#]

Example 2: Ignore case

[root@centos7 ~#]locate -i ~/d
/root/Desktop/root/Documents/root/Downloads
/root/d1
/root/dd
/var/lib/pcp/pmdas/root/domain.h
[root@centos7 ~#]

Example 3: Update the database

[root@centos7 ~#]locate ~/a
/root/anaconda-ks.cfg
[root@centos7 ~#]updatedb
[root@centos7 ~#]locate ~/a
/root/a.sh
/root/anaconda-ks.cfg
[root@centos7 ~#]

1.2 find

1.2.1 The main purpose

The find command is a real-time finder, and the completion of the document by traversing to find the specified path; when you use this command, if not selected parameters, then find subdirectories with files in the current directory and displays it; in addition, any parameters located before the string will be treated as a directory name you want to find. Because real-time traversing find, find the following features: accurate real-time search, a search may only slow the user directory with read and execute permissions.

1.2.2 find syntax:

find [OPTION]... [查找路径] [查找条件] [处理动作]

Search Path: Specifies the targets path, the default is the current directory

Search Terms: specified search criteria can be a standard file name, size, type, permissions, and so on; the default is to find all the files in the specified path

Actions: do operations that meet the conditions file, the default output to the screen

1.2.3 Search Terms

1. 根据文件名和inode查找
2. 根据属主、属组查找
3. 根据文件类型查找
4. 根据逻辑组合条件查找
5. 根据文件大小来查找
6. 根据时间戳来查找 
7. 根据权限来查找

1.2.4 processing operation

1. -print: 默认动作,显示至屏幕
2. -ls: 类似于对查找到的文件执行 ls -l 命令
3. -delete: 删除查找到的文件
4. -fls file: 查找到的所有长格式的信息保存至指定文件中
5. -ok COMMMAND {} \;   对查找到的每个文件执行由COMMAND指定的命令,且都会交互式要求用户确认
6. -exec COMMAND {} \;  对查找到的每个文件执行由COMMAND指定的命令;
7. {}: 用于引用查找至的文件名称自身
8. find 传递查找到的文件至后面指定的命令时,查找到所有符号条件的文件一次性传递给后面的命令
9. 有些命令不能接受过多的参数,此时命令执行可能会失败,用 xargs 来规避此问题
    find |xargs COMMAND

1.2.5 Common parameters

1.2.5.1 file name and inode categories:

    -name "文件名称": 支持使用glob, *, ?, [], [^]

    -iname "文件名称": 不区分字母大小写

    -inum n: 按inode号查找

    -somefile name: 相同的inode号文件

    -links n: 链接数为n的文件

    -regex "PATTERN": 以PATTERN匹配整个文件路径字符串,而不仅仅是文件名称

1.2.5.2 owner class is a group:

    -user USERNAME: 查找属主为指定用户(UID)的文件

    -group GROUPNAME: 查找属组为指定组(GID)的文件

    -uid UserID: 查找属主为指定的UID号的文件

    -gid GroupID: 查找属组为指定的GID号的文件

    -nouser: 查找没有属主的文件

    -nogroup: 查找没有属组的文件

1.2.5.3 file type categories:

b      block (buffered) special

c      character (unbuffered) special

d      directory

p      named pipe (FIFO)f      regular file

l      symbolic  link

s      socket

1.2.5.4 logical combination of conditions categories:

A combination of conditions:

与:-a
或:-o
非:-not, !

Morgan's law:

(非P) 或(非Q) = 非(P且Q)
(非P) 且 (非Q) = 非(P或Q)

1.2.5.5 File size categories:

-size [+|-]#UNIT
    常用单位:k,M,G 
#UNIT: (#-1,#]
    如:5M 表示 (4M,5M]
-#UNIT: [0,#-1]
    如:-5M 表示 [0,5M]
+#UNIT: (#,oo)
    如:+5M 表示 (6M,oo)

About file size classes of explanation: Why -size 5M 5M but still find accurate representation (4M, 5M], imagine what refers to the file size is the size of a file or data, including the size of the metadata that you find? ? size of meaningful metadata file size, but it certainly contains metadata size, and file size we generally find files often consider is the size of the data file; in addition, the document has little meaning to pinpoint a certain size; so here there will be a floating size of a unit.

1.2.5.6 timestamp categories:

以”天”为单位:
    -atime [+|-]#        
        #: [#,#+1)
        +#: [#+1,oo)        
        -#: [0,#)
    -mtime    
    -ctime

以“分钟”为单位:
    -amin    
    -mmin    
    -cmin

On the interpretation of the time stamp class: Why -atime is [3,4) 3 shows, this very good explanation, we here say time is the time period instead of a time, a "day" and a "minute" refer to a period of time, only [3, 4) this half-closed half-open interval in order to fully represent the third day.

1.2.5.7 Permissions categories:

-perm [/|-]MODE
    MODE: 精确匹配权限
    /MODE: 任何一类(u,g,o)对象的权限中只要能一位匹配即可,属于或关系。以前用'+',CentOS 7以'/'替代之
    -MODE: 每一类对象都必须同时拥有指定权限,属于与关系 
    0:表示不关注

Example:

find -perm 644 表示要严格匹配644的文件
find -perm +222 表示u,g,o任何一类用户有写权限即匹配
find -perm -222 表示仅严格匹配写权限,即每个用户必须要有写权限
find -perm -002 表示仅严格匹配other用户的写权限

1.2.6 Example of use:

Example 1: The backup configuration files to a specified directory and add the extension .org
[root@localhost ~]# find . -name "*.conf" -exec cp -r {} /testdir/{}.org \; 
[root@localhost ~]# cd /testdir/
[root@localhost testdir]# ls
a.conf.org  b.conf.org
[root@localhost testdir]#
There is time for more than three days of temporary files as young owner of Example 2 :. prompted to delete
[root@localhost ~]# find /tmp -ctime +3 -user young -exec rm -fr {} \;
[root@localhost ~]#
Example 3: Find the file can be written by other users in the home directory
[root@localhost ~]# find ~ -perm -002
/root/num
[root@localhost ~]# find ~ -perm -002 -exec chmod o-w {} \;
[root@localhost ~]# ll num
--w--w---- 1 root root 35 Jan 21 05:55 num
Example 4: Find the / var directory subordinate to the main root, and all the files belong to the group mail
    [root@localhost ~]# find /var -user root  -group mail -ls #默认关系就是与
1179652    4 drwxrwxr-x   2 root     mail         4096 Jan 23 11:04 /var/spool/mail
Example 5: Find / var directory under does not belong to root, lp, all the files gdm
[root@localhost ~]# find /var ! -user root ! -user lp ! -user gdm
实例6:查找/var目录下最近一周内其内容修改过,同时属主不为root,也不是postfix的文件
    [root@localhost ~]# find /var/ -mtime -7 ! -user root ! -user postfix -ls
1179676    4 drwx------   3 daemon   daemon       4096 Jan 23 11:04 /var/spool/at
524399    4 drwx------   2 nginx    nginx        4096 Jan 23 03:16 /var/log/nginx
524413    0 -rw-r--r--   1 nginx    root            0 Jan 23 03:16 /var/log/nginx/access.log
524391    0 -rw-r--r--   1 nginx    root            0 Jan 21 03:44 /var/log/nginx/error.log
132174    4 drwx------   3 nginx    nginx        4096 Jan 21 03:44 /var/lib/nginx
132175    4 drwx------   7 nginx    nginx        4096 Jan 21 03:44 /var/lib/nginx/tmp
132173    4 drwx------   2 nginx    root         4096 Jan 21 03:44 /var/lib/nginx/tmp/client_body
132219    4 drwx------   2 nginx    root         4096 Jan 21 03:44 /var/lib/nginx/tmp/proxy
132221    4 drwx------   2 nginx    root         4096 Jan 21 03:44 /var/lib/nginx/tmp/uwsgi
132222    4 drwx------   2 nginx    root         4096 Jan 21 03:44 /var/lib/nginx/tmp/scgi
132220    4 drwx------   2 nginx    root         4096 Jan 21 03:44 /var/lib/nginx/tmp/fastcgi
实例7:查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件
[root@bash ~]# find / -nouser -o -nogroup -a -atime -7
实例8:查找/etc目录下大于1M且类型为普通文件的所有文件
[root@bash ~]# find /etc/ -size +1M -type f
/etc/selinux/targeted/policy/policy.29
/etc/udev/hwdb.bin
实例9:查找/etc目录下所有用户都没有写权限的文件
[root@bash ~]# find /etc/ ! -perm /222
/etc/pki/ca-trust/extracted/java/cacerts
/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
/etc/lvm/profile/cache-mq.profile
/etc/lvm/profile/cache-smq.profile
/etc/lvm/profile/command_profile_template.profile
/etc/lvm/profile/metadata_profile_template.profile
/etc/lvm/profile/thin-generic.profile
/etc/lvm/profile/thin-performance.profile
/etc/openldap/certs/password
/etc/gshadow
/etc/dbus-1/system.d/cups.conf
/etc/shadow
/etc/gshadow-
/etc/ld.so.conf.d/kernel-3.10.0-327.el7.x86_64.conf
/etc/shadow-
/etc/udev/hwdb.bin
/etc/machine-id
/etc/pam.d/cups
/etc/sudoers
实例10:查找/etc目录下至少有一类用户没有执行权限的文件
[root@bash ~]# find /etc/ ! -perm -111 # 至少有一类用户没有就是所有用户都没有
实例11:.查找/etc/init.d目录下,所有用户都有执行权限,且其它用户有写权限的文件
[root@bash ~]# find /etc/init.d -perm -113
/etc/init.d

或者

[root@bash ~]# find /etc/init.d -perm -111 -perm -002
/etc/init.d
实例12:摩根定律找出/tmp目录下,属主不是root,且文件名不以f开头的文件
[root@centos7 ~]#find /tmp \( -not -user root -a -not -name 'f*' \) -ls
即
[root@centos7 ~]#find /tmp -not \( -user root -o -name 'f*' \) -ls
实例13:查找/etc/下,除/etc/sane.d目录的其它所有.conf后缀的文件
[root@bash ~]# find /etc -path '/etc/sane.d' -prune -o -name '*.conf'
实例14:匹配文件路径或文件
[root@bash ~]# find /usr/ -path '*local'
/usr/bin/abrt-action-analyze-ccpp-local
/usr/share/doc/postfix-2.10.1/examples/qmail-local
/usr/share/aclocal
/usr/libexec/postfix/local
/usr/local
实例15:基于正则表达式匹配文件路径
[root@bash ~]# find . -regex ".*txt$"              
./.mozilla/firefox/4dqu966q.default/revocations.txt
./vimrc/spf13-vim/LICENSE.txt
./a.txt

1.3 which

1.3.1 命令功能:

which指令会在PATH变量指定的路径中,搜索某个系统命令的位置,并且返回第一个搜索结果。

1.3.2 命令格式:

which 可执行文件名称 

1.3.3 命令参数:

-n  指定文件名长度,指定的长度必须大于或等于所有文件中最长的文件名。

-p  与-n参数相同,但此处的包括了文件的路径。

-w  指定输出时栏位的宽度。

-V  显示版本信息

1.3.4 使用实例:

实例1:查找文件、显示命令路径

命令:

which lsmod

输出:

[root@localhost ~]# which pwd

/bin/pwd

[root@localhost ~]#  which adduser

/usr/sbin/adduser

[root@localhost ~]#

说明:

which 是根据使用者所配置的 PATH 变量内的目录去搜寻可运行档的!所以,不同的 PATH 配置内容所找到的命令当然不一样的!

实例2:用 which 去找出 which

命令:

which which

输出:

[root@localhost ~]# which which

alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot  --show-tilde'

  /usr/bin/which

[root@localhost ~]#

说明:

竟然会有两个 which ,其中一个是 alias 这就是所谓的『命令别名』,意思是输入 which 会等於后面接的那串命令!

二.文件打包与压缩

常用打包压缩格式

.zip  .gz  .bz2  .tar  .tar.gz  .tar.bz2

2.1 .zip 格式

1.压缩

压缩文件

zip 压缩文件名 源文件

压缩目录

zip -r 压缩文件名 源目录
  • 实例
[vagrant/tmp] ]$zip a.zip a.md
  adding: a.md (stored 0%)
[vagrant/tmp] ]$zip -r abc.zip abc
  adding: abc/ (stored 0%)
  adding: abc/def/ (stored 0%)
  adding: abc/def/ghi/ (stored 0%)
[vagrant/tmp] ]$ll
drwxrwxr-x 3 vagrant       vagrant       4.0K Apr 19 00:53 abc/
-rw-rw-r-- 1 vagrant       vagrant        454 Apr 19 00:55 abc.zip
-rw-rw-r-- 1 vagrant       vagrant          0 Apr 19 00:53 a.md
-rw-rw-r-- 1 vagrant       vagrant        158 Apr 19 00:55 a.zip

2. 解压缩

unzip 压缩文件名 [-d <文件解压缩后所要存储的目录>]
  • 实例
[vagrant/tmp] ]$mkdir zip
[vagrant/tmp] ]$unzip a.zip -d zip
Archive:  a.zip
 extracting: zip/a.md
[vagrant/tmp] ]$unzip abc.zip -d zip
Archive:  abc.zip
   creating: zip/abc/
   creating: zip/abc/def/
   creating: zip/abc/def/ghi/
[vagrant/tmp] ]$ll zip
drwxrwxr-x 3 vagrant vagrant 4.0K Apr 19 00:53 abc/
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 00:53 a.md

2.2 .gz 格式

1. 压缩

压缩文件

gzip 源文件

注意:源文件会消失!

gzip -c 源文件 > 压缩文件

压缩文件,源文件保留

gzip -r 目录

压缩目录下所有子文件,但是不能压缩目录

压缩目录

gzip 不能压缩目录

  • 实例
[vagrant/tmp] ]$gzip -c a.md > a.md.gz
[vagrant/tmp] ]$ll
drwxrwxr-x 3 vagrant       vagrant       4.0K Apr 19 00:53 abc/
-rw-rw-r-- 1 vagrant       vagrant          0 Apr 19 00:53 a.md
-rw-rw-r-- 1 vagrant       vagrant         25 Apr 19 04:11 a.md.gz
[vagrant/tmp] ]$ll abc
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 04:12 a
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 04:12 b
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 04:12 c
[vagrant/tmp] ]$gzip -r abc
[vagrant/tmp] ]$ll abc
-rw-rw-r-- 1 vagrant vagrant   22 Apr 19 04:12 a.gz
-rw-rw-r-- 1 vagrant vagrant   22 Apr 19 04:12 b.gz
-rw-rw-r-- 1 vagrant vagrant   22 Apr 19 04:12 c.gz

2. 解压缩

gzip -d 压缩文件

gunzip 压缩文件
  • 实例
[vagrant/tmp/tmp] ]$gzip -d a.md.gz
[vagrant/tmp/tmp] ]$ll
drwxrwxr-x 3 vagrant vagrant 4.0K Apr 19 04:13 abc/
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 04:11 a.md
[vagrant/tmp/tmp] ]$gzip -dr abc/
[vagrant/tmp/tmp] ]$ll abc
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 04:12 a
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 04:12 b
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 04:12 c

2.3 .bz2 格式

1. 压缩

压缩文件

1. bzip2 源文件

注意:源文件会消失!

2. bzip2 -k 源文件

压缩文件,源文件保留

压缩目录

bzip2 不能压缩目录

  • 实例
[vagrant/tmp/tmp] ]$bzip2 -k a.md
[vagrant/tmp/tmp] ]$ll
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 04:11 a.md
-rw-rw-r-- 1 vagrant vagrant   14 Apr 19 04:11 a.md.bz2
[vagrant/tmp/tmp] ]$rm a.md.bz2
[vagrant/tmp/tmp] ]$bzip2 a.md
[vagrant/tmp/tmp] ]$ll
-rw-rw-r-- 1 vagrant vagrant   14 Apr 19 04:11 a.md.bz2

2. 解压缩

bzip2 -d 压缩文件

解压缩,默认不保留压缩文件。加 -k 可保留压缩文件

gunzip 压缩文件

解压缩,默认不保留压缩文件。加 -k 可保留压缩文件

  • 实例
[vagrant/tmp/tmp] ]$bzip2 -dk a.md.bz2
[vagrant/tmp/tmp] ]$ll
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 04:11 a.md
-rw-rw-r-- 1 vagrant vagrant   14 Apr 19 04:11 a.md.bz2
[vagrant/tmp/tmp] ]$rm a.md
[vagrant/tmp/tmp] ]$bunzip2 -k a.md.bz2
[vagrant/tmp/tmp] ]$ll
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 04:11 a.md
-rw-rw-r-- 1 vagrant vagrant   14 Apr 19 04:11 a.md.bz2
[vagrant/tmp/tmp] ]$rm a.md
[vagrant/tmp/tmp] ]$bzip2 -d a.md.bz2
[vagrant/tmp/tmp] ]$ll
-rw-rw-r-- 1 vagrant vagrant    0 Apr 19 04:11 a.md

2.4 .tar 格式

1. 打包

tar -cvf 打包文件名 源文件或目录
  • 选项

-c : 打包
-v : 显示打包过程
-f : 指定打包后的文件名

  • 实例
[vagrant/tmp/tmp] ]$tar -cvf abc.tar abc
abc/
abc/def/
abc/def/ghi/
abc/a
abc/b
abc/c
[vagrant/tmp/tmp] ]$ll
drwxrwxr-x 3 vagrant vagrant 4.0K Apr 19 04:22 abc/
-rw-rw-r-- 1 vagrant vagrant  10K Apr 19 07:02 abc.tar

2. 解打包

tar -xvf 打包文件名
  • 选项

-x : 解打包

  • 实例
vagrant/tmp/tmp] ]$tar -xvf abc.tar
abc/
abc/def/
abc/def/ghi/
abc/a
abc/b
abc/c
[vagrant/tmp/tmp] ]$ll
drwxrwxr-x 3 vagrant vagrant 4.0K Apr 19 04:22 abc/
-rw-rw-r-- 1 vagrant vagrant  10K Apr 19 07:02 abc.tar

2.5 .tar.gz 格式

其实,.tar.gz 格式是先将文件或目录打包文 .tar 格式,再压缩为 .gz 格式

1. 压缩

tar -zcvf 压缩包名.tar.gz 源文件
  • 选项

-z : 压缩为 .tar.gz 格式

2. 解压缩

tar -zxvf 压缩包名.tar.gz
  • 选项

-x : 解压缩
-t : 查看压缩保内文件,但是不解压缩

  • 实例
[vagrant/tmp/tmp] ]$tar -zcvf abc.tar.gz abc
abc/
abc/def/
abc/def/ghi/
abc/a
abc/b
abc/c
[vagrant/tmp/tmp] ]$ll
total 8.0K
drwxrwxr-x 3 vagrant vagrant 4.0K Apr 19 04:22 abc/
-rw-rw-r-- 1 vagrant vagrant  204 Apr 19 07:27 abc.tar.gz
[vagrant/tmp/tmp] ]$rm -rf abc
[vagrant/tmp/tmp] ]$tar -ztvf abc.tar.gz
drwxrwxr-x vagrant/vagrant   0 2018-04-19 04:22 abc/
drwxrwxr-x vagrant/vagrant   0 2018-04-19 00:52 abc/def/
drwxrwxr-x vagrant/vagrant   0 2018-04-19 00:52 abc/def/ghi/
-rw-rw-r-- vagrant/vagrant   0 2018-04-19 04:12 abc/a
-rw-rw-r-- vagrant/vagrant   0 2018-04-19 04:12 abc/b
-rw-rw-r-- vagrant/vagrant   0 2018-04-19 04:12 abc/c
[vagrant/tmp/tmp] ]$ll
total 4.0K
-rw-rw-r-- 1 vagrant vagrant 204 Apr 19 07:27 abc.tar.gz
[vagrant/tmp/tmp] ]$tar -zxvf abc.tar.gz
abc/
abc/def/
abc/def/ghi/
abc/a
abc/b
abc/c
[vagrant/tmp/tmp] ]$ll
total 8.0K
drwxrwxr-x 3 vagrant vagrant 4.0K Apr 19 04:22 abc/
-rw-rw-r-- 1 vagrant vagrant  204 Apr 19 07:27 abc.tar.gz

2.6 .tar.bz2 格式

其实,.tar.bz2 格式是先将文件或目录打包文 .tar 格式,再压缩为 .bz2 格式

1. 压缩

tar -jcvf 压缩包名.tar.bz2 源文件
  • 选项

-j : 压缩为 .tar.bz2 格式

2. 解压缩

tar -jxvf 压缩包名.tar.bz2
  • 选项

-x : 解压
-t : 查看压缩保内文件,但是不解压缩
-C : 指定解压的目录(注意,该选项必须放在后面)

  • 实例
[vagrant/tmp/tmp] ]$tar -jcvf abc.tar.bz2 abc
abc/
abc/def/
abc/def/ghi/
abc/a
abc/b
abc/c
[vagrant/tmp/tmp] ]$ll
total 8.0K
drwxrwxr-x 3 vagrant vagrant 4.0K Apr 19 04:22 abc/
-rw-rw-r-- 1 vagrant vagrant  210 Apr 19 07:33 abc.tar.bz2
[vagrant/tmp/tmp] ]$tar -jtvf abc.tar.bz2
drwxrwxr-x vagrant/vagrant   0 2018-04-19 04:22 abc/
drwxrwxr-x vagrant/vagrant   0 2018-04-19 00:52 abc/def/
drwxrwxr-x vagrant/vagrant   0 2018-04-19 00:52 abc/def/ghi/
-rw-rw-r-- vagrant/vagrant   0 2018-04-19 04:12 abc/a
-rw-rw-r-- vagrant/vagrant   0 2018-04-19 04:12 abc/b
-rw-rw-r-- vagrant/vagrant   0 2018-04-19 04:12 abc/c
[vagrant/tmp/tmp] ]$tar -jxvf abc.tar.bz2 -C /tmp
abc/
abc/def/
abc/def/ghi/
abc/a
abc/b
abc/c
[vagrant/tmp/tmp] ]$ll /tmp/
drwxrwxr-x 3 vagrant       vagrant       4.0K Apr 19 04:22 abc/
drwxrwxr-x 3 vagrant       vagrant       4.0K Apr 19 07:33 tmp/

Guess you like

Origin www.cnblogs.com/MessiXiaoMo3334/p/11372780.html