linux系统下文件查找与打包解压

34 篇文章 0 订阅

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目录)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值