一、文件查找
1、which/whereis/whatis
which 只能查询命令
[root@aliyun ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
whereis 可以查看命令和配置文件的位置
[root@aliyun ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
whatis 查询命令在哪章和下面一样
[root@aliyun ~]# whatis ls
ls (1) - list directory contents
[root@aliyun ~]# man -f ls
ls (1) - list directory contents
2、locate
维护着一个查询数据库
[root@qfedu.com ~]# vim /etc/updatedb.conf
1)文件系统类型
2)目录
如果被更改之后,需要更新数据库
[root@qfedu.com ~]# updatedb 手动更新数据库
[root@qfedu.com ~]# locate 被查找的关键字
[root@qfedu.com ~]# locate *.txt
*是通配符
3、find
语法
find 查找位置 查找条件
按名称来查找
-name 文件名
-iname 不区分大小写
find /etc -name 'passwd'
[root@t1 ~]# find /etc -name passwd
/etc/pam.d/passwd
/etc/passwd
按大小查找
-zise 文件类型
[root@t1 ~]# find /etc/ -size +1M
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31
[root@t1 ~]# find /etc/ -size -1M
/etc/crypttab
/etc/environment
查找大于1M小于10M的文件
-a可以换成-and
-o可以换成-or
[root@t1 ~]# find /etc -size +1M -a -size -10M
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31
按文件类型查找
-type
[root@t1 ~]# find /etc -type d
/etc
/etc/fonts
-exec 对之前查找出来的文件做进一步操作
-ok 和-exec一样,只不过多了提示
[root@t1 opt]# find /opt -name 'a.txt' -exec rm -f {} \;
[root@t1 opt]# find /opt -name 'aa.txt' -ok rm -f {} \;
< rm ... /opt/aa.txt > ? y
按时间查找
time表示单位是天
min 表示分钟
-atime -mtime -ctime
-amin -mmin -cmin
access时间 modify时间 change时间
查找两分钟前访问过的文件
[root@qfedu.com ~]# find /tmp -amin -2
/tmp/a.txt
二、文件打包及压缩
归档:
[root@qfedu.com ~]# tar cvf file.tar 被打包的文件 ...
[root@qfedu.com ~]# tar cvf abc.tar a b c d e
解包:
[root@qfedu.com ~]# tar xvf 打包文件 -C /opt/
-C 指定解包路径
gzip类型的归档压缩
# tar cvzf test.tar.gz a.txt b.txt file1 file2
# tar xvzf test.tar.gz
c create 创建
v verbose 显示详细过程
f file
x extract 抽取 解开
z gzip类型
j bzip2类型
bzip2类型的归档压缩
# tar cvjf test.tar.bz2 a.txt b.txt file1 file2
# tar xvjf test.tar.bz2