设为首页 收藏本站
查看: 1502|回复: 0

[经验分享] linux find tar

[复制链接]
累计签到:2 天
连续签到:1 天
发表于 2019-2-17 12:17:27 | 显示全部楼层 |阅读模式
  命令文件: which ls  (echo $PATH)
  任意文件:locate
  -  (updatedb)
  find
  find [options] [path...] [expression]
  按文件名:
  [root@station230 ~]# find /etc -name "ifcfg-eth0"
  [root@station230 ~]# find /etc -iname "ifcfg-eth0"//-i忽略大小写
  [root@station230 ~]# find /etc -iname "ifcfg-eth*"
  按大小:
  [root@station230 ~]# find /etc -size +5M//大于5M
  [root@station230 ~]# find /etc -size 5M
  [root@station230 ~]# find /etc -size -5M
  [root@station230 ~]# find /etc -size +5M -ls//-ls选项
  按时间找(atime,mtime,ctime)
  [root@station230 ~]# find /etc -mtime +5//修改时间超过5天
  [root@station230 ~]# find /etc -mtime 5//修改时间等于5天
  [root@station230 ~]# find /etc -mtime -5//修改时间5天以内
  按文件属主、属组找
  [root@station230 ~]# find /home -user jack//属主是jack的文件
  [root@station230 ~]# find /home -group jack//属组是jack组的文件
  [root@station230 ~]# find /home -user jack -group alice
  [root@station230 ~]# find /home -user jack -a  -group alice
  [root@station230 ~]# find /home -user jack -o  -group alice
  [root@station230 ~]# find /home -nouser
  [root@station230 ~]# find /home -nogroup
  [root@station230 ~]# find /home -ls -nouser -o -nogroup
  按文件类型:
  [root@station230 ~]# find /dev -type f//f普通
  [root@station230 ~]# find /dev -type d//d目录
  [root@station230 ~]# find /dev -type l//l链接
  [root@station230 ~]# find /dev -type b//b块设备
  [root@station230 ~]# find /dev -type c//c字符设备
  [root@station230 ~]# find /dev -type s//s套接字
  [root@station230 ~]# find /dev -type p//p管道文件
  -inum n
  find / -inum 31064284           //根据inode 查找
  按权限:
  [root@station230 dir8]# find . -perm 644 -ls
  [root@station230 dir8]# find . -perm -644 -ls
  [root@station230 dir8]# find . -perm -600 -ls
  [root@station230 ~]# find /sbin -perm -4000 -ls//包含set uid
  [root@station230 ~]# find /sbin -perm -2000 -ls//包含set gid
  [root@station230 ~]# find /sbin -perm -1000 -ls//包含sticky
  找到后处理的动作:
  [root@station230 ~]# find /etc -name "ifcfg-eth0" -exec cp -rf {} /tmp \;
  [root@station230 dir8]# find . -name "file*" -exec rm -rvf {} \;
  1. 将/etc/中的所有目录(仅目录)复制到/tmp下,目录结构不变
  [root@station230 ~]# find /etc -type d -exec mkdir -p /tmp/{}  \;
  2. 将/etc目录复制到/var/tmp/,
  将/var/tmp/etc中的所有目录设置权限777(仅目录)
  将/var/tmp/etc中所有文件权限设置为666
  [root@station230 tmp]# find etc -type d -exec chmod 777 {} \;
  [root@station230 tmp]# find etc -type f -exec chmod 666 {} \;
  [root@station230 tmp]# find etc ! -type d -exec chmod 666 {} \;
  3. 创建目录/dir1,在/dir1中创建文件file1 file2 file3
  使用find查找并删除 除了file2以外的所有文件
  [root@station230 ~]# mkdir /dir4
  [root@station230 ~]# touch /dir4/file{1..100}
  [root@station230 etc]# find . ! -name ntp.conf -exec rm -rf {} \;
  [root@station230 dir4]# find . ! -name file50 -a ! -name file70 -exec rm -rf {} \;
  ===文件打包、压缩
  ==打包
  [root@station230 ~]# tar -cvf etc1.tar /etc//c创建 v详细 f打包后文件名
  [root@station230 ~]# tar -cf etc2.tar /etc
  [root@station230 ~]# ll -h etc*
  -rw-r--r-- 1 root root 104M 10-29 12:10 etc1.tar
  -rw-r--r-- 1 root root 104M 10-29 12:11 etc2.tar
  ==压缩
  [root@station230 ~]# gzip etc1.tar
  [root@station230 ~]# bzip2 etc2.tar
  [root@station230 ~]#
  [root@station230 ~]# ll -h etc*
  -rw-r--r-- 1 root root  12M 10-29 12:10 etc1.tar.gz
  -rw-r--r-- 1 root root 8.0M 10-29 12:11 etc2.tar.bz2
  ==解压
  [root@station230 ~]# gzip -d etc1.tar.gz
  [root@station230 ~]# bzip2 -d etc2.tar.bz2
  ==解包
  [root@station230 ~]# tar -xvf etc1.tar//解包到当前目录
  [root@station230 ~]# tar -xf etc2.tar -C /var/tmp///-C重定向到/var/tmp目录
  =====================================================================================
  ===打包,压缩===
  [root@station230 ~]# tar -czf etc1.tar.gz /etc//-z 调用gzip
  [root@station230 ~]# tar -cjf etc2.tar.bz2 /etc//-j 调用bzip2
  ===解包,解压===
  [root@station230 ~]# tar -xvf etc1.tar.gz//无需指定解压工具,tar会自动判断gzip或bzip2
  [root@station230 ~]# tar -xvf etc2.tar.bz2  -C /tmp
  [root@station230 ~]# tar xvf etc1.tar.gz
  # unzip 1.zip
  # *.rar




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-673563-1-1.html 上篇帖子: linux shell基本特性 下篇帖子: linux kernel modules
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表