一、實時的查找(不指定目錄在當前目錄下查找)chrome
二、多條件儘量精確地定位搜索對象(不指定條件列出目錄中的全部文件)session
三、find 能夠鏈接命令對查找出的結果直接處理app
1)、-exec or -ok 2)、{}匹配查詢出的結果 3)、整條命令的結尾Space\;
find 目錄 條件 動做工具
-type 類型(f d l p c b)spa
[root@localhost ~]# find -type d . ./.cache ./.cache/dconf ./.cache/abrt ./.cache/mozilla ./.cache/mozilla/firefox ./.cache/mozilla/firefox/tv48miwc.default ./.cache/mozilla/firefox/tv48miwc.default/cache2 ./.cache/mozilla/firefox/tv48miwc.default/cache2/entries ./.cache/mozilla/firefox/tv48miwc.default/cache2/doomed ./.cache/mozilla/firefox/tv48miwc.default/thumbnails ./.cache/mozilla/firefox/tv48miwc.default/startupCache ./.cache/mozilla/firefox/tv48miwc.default/OfflineCache ./.cache/mozilla/firefox/tv48miwc.default/safebrowsing ./.dbus ./.dbus/session-bus ./.config ./.config/abrt
-name 名稱(-iname 對文件名的大小寫不敏感)操作系統
[root@localhost ~]# find /etc/ -name passwd /etc/pam.d/passwd /etc/passwd [root@localhost ~]#
-size 大小 +1M 大於1M, -1M 小於1M,1M 等於1Mfirefox
[root@localhost ~]# find /etc/ -name passwd /etc/pam.d/passwd /etc/passwd [root@localhost ~]# find /boot -size +1M /boot/grub2/fonts/unicode.pf2 /boot/System.map-3.10.0-693.el7.x86_64 /boot/vmlinuz-3.10.0-693.el7.x86_64 /boot/initrd-plymouth.img /boot/initramfs-0-rescue-17864a38d41d4b6e860d389f6c75531b.img /boot/vmlinuz-0-rescue-17864a38d41d4b6e860d389f6c75531b /boot/initramfs-3.10.0-693.el7.x86_64.img /boot/initramfs-3.10.0-693.el7.x86_64kdump.img [root@localhost ~]#
-user 文件擁有者code
[root@localhost ~]# find /home -user root /home /home/ateam-text /home/ateam-text/newfile1 /home/ateam-text/newdir1 /home/ateam-text/newfile2 /home/ateam-text/newdir2 /home/ateam-text/newfile3 /home/ateam-text/newdir3 /home/ateam-text/newfile4 /home/ateam-text/newdir4 [root@localhost ~]#
-group 文件屬組對象
[root@localhost ~]# find /var/ -group mail /var/spool/mail /var/spool/mail/rpc /var/spool/mail/zhang /var/spool/mail/alex /var/spool/mail/root [root@localhost ~]#
-perm權限blog
[root@localhost ~]# find -perm 755 ./.cache/abrt ./.cache/mozilla/firefox/tv48miwc.default/startupCache ./.cache/mozilla/firefox/tv48miwc.default/safebrowsing ./.config ./.config/abrt ./.mozilla ./.mozilla/extensions ./.mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384} ./.mozilla/firefox/tv48miwc.default/storage ./.mozilla/firefox/tv48miwc.default/storage/permanent ./.mozilla/firefox/tv48miwc.default/storage/permanent/chrome ./.mozilla/firefox/tv48miwc.default/storage/permanent/chrome/idb ./.mozilla/firefox/tv48miwc.default/storage/permanent/chrome/idb/2918063365piupsah.files ./Desktop [root@localhost ~]#
-perm +222 anyone +表明(或)三組權限匹配其中之一
-perm -222 everyone -表明(與)三組權限同時匹配
-mtime +3 從當天向歷史天數推算的第三天前
-atime -3 從當前向歷史天數推算的前三天至當天這個段範圍
-ctime 3 從當天向歷史天數推算的第三天
-o 或
-not 非
-ls 詳細信息
[root@localhost ~]# find /var/mail/ \( -user zhang -o -user root \) -ls 50333136 0 drwxrwxr-x 2 root mail 54 8月 24 09:22 /var/mail/ 51743355 0 -rw-rw---- 1 zhang mail 0 8月 20 19:23 /var/mail/zhang 51751716 8 -rw------- 1 root mail 5485 8月 24 09:20 /var/mail/root [root@localhost ~]#
find /etc/ -perm -002 -exec chmod o-w {} \; find /etc/ -name "*.conf" -ok cp {} {}.bak \; find /tmp/ -size +100M -exec rm {} \; find /tmp -user user1 -atime +3 -exec rm {} \; find -not -perm +111 -name "*.sh" -exec chmod u+x {} \;
用rm刪除太多文件的時候,可能會獲得一個錯誤信息:/bin/rm Argument list too long,用xargs去避免這個問題
[root@localhost ~]# find /tmp/ -name '*.txt' -print0 | xargs -0 rm -f [root@localhost ~]#
xargs -0將\0做爲定界符
查找全部的TXT文件,並壓縮
[root@localhost ~]# find . -name '*.txt' -print | xargs tar -acvf file.tar.gz [root@localhost ~]#
tar類Unix操做系統上的打包工具,能夠將多個文件合併爲一個文件,便於傳輸,備份
-c --create 建立新的tar文件
-x --extract, --get 解開tar文件
-t --list列出tar文件中包含的文件的信息
-r --append 附加新的文件到tar文件中
-f --file[主機名:]文件名 指定要處理的文件名
-j --bzip2調用bzip2執行壓縮
-z --gzip 調用gizip執行
建立
[root@localhost test]# tar -cvf home_backup.tar /home/zhang/ [root@localhost test]#
查看
[root@localhost test]# tar -tf home_backup.tar ^C [root@localhost test]# 文件太多,不展現
釋放
[root@localhost test]# tar -xvf home_backup.tar [root@localhost test]#
其餘的壓縮包操做相似,具體請百度。。