which
命令查找
[root@localhost ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
find
文件查找,针对文件名
[root@localhost ~]# find /etc -name "touch"
按文件大小查找
[root@localhost ~]# find /etc -size +5M(查找大于5M的文件)
[root@localhost ~]# find /etc -size 5M(查找等于5M的文件)
[root@localhost ~]# find /etc -size -5M(查找小于5M的文件)
指定查找的目录深度
[root@localhost ~]# find / -maxdepth 4 -a -name "touch"
按文件属主,属组找
[root@localhost ~]# find /home -user 1 (查找属主是 1 的文件)
[root@localhost ~]# find /home -group 2 (查找属组是 2 的文件)
按文件类型
[root@localhost ~]# find /tmp -tupe f
[root@localhost ~]# find /dev -type b
f普通文件
b块设备文件
d目录
p管道
l链接
按文件权限
[root@localhost ~]# find -perm644 -ls
-ls是find的动作之一,精确权限
找到后的动作
找到后删除
[root@localhost ~]# find /etc -name "touch" -delete
找到后复制
[root@localhost ~]# find /etc -name "touch" -ok cp -rvf /tmp \:
locate
文件查找,依赖数据库
tar
tar命令是unix/linux系统中备份文件的可靠方法,几乎可以工作于任何环境中,它的使用权是所有用户。建议针对目录
打包,压缩
[root@localhost ~]# tar -cf etc.tar /etc
[root@localhost ~]# tar -czf etc-gzip.tar.gz /etc(z是gizp)
[root@localhost ~]# tar -cjf etc -bzip.tar.ba /etc(j是bzip)
[root@localhost ~]# tar -cjf etc -xzip.tar.xz /etc(j是xzip)
观察几个包的体积
[root@localhost ~]# ll -h etc*
-rw-r--r--. 1 root root 29M 8月 4 19:22 etc.tar
-rw-r--r--. 1 root root 9.9M 8月 4 19:24 etc-gzip.tar.gz
-rw-r--r--. 1 root root 8.7M 8月 4 19:24 etc-bzip.tar.bz
-rw-r--r--. 1 root root 8.7M 8月 4 19:25 etc-xzip.tar.xz
压缩速度和压缩体积成反比
解压,解包
查看,不解压
[root@localhost ~]# tar -tf etc.tar (t查看,f文件名)
解压缩
[root@localhost ~]# tar xf etc.tar (直接解压)
[root@localhost ~]# tar xvf etc.tar -C /tmp (-C重定向到/tmp目录)