搜索查找指令

  1. find從指定目錄向下遞歸遍歷其各個子目錄,將滿足條件的文件或者目錄顯示在終端
  • find [搜索範圍] [選項]
  • 按文件名查找/home查找a.txt文件
[root@localhost home]# find /home -name a.txt
/home/a.txt
  • 按擁有者:查找/root目錄下,用戶名稱爲root的文件
[root@localhost home]# find /root -user root
/root
/root/.cache
  • 查找整個linux系統下大於20M的文件(+n大於,-n小於,n等於)
[root@localhost home]# find / -size +20M
/boot/initramfs-0-rescue-556c815aa38f7d4c833ca6590b2e99e0.img
/boot/initramfs-4.18.0-147.el8.x86_64.img
/proc/kcore
  • 查找以.txt結尾的
[root@localhost home]# find / -name *.txt
/home/a.txt
  1. locate 指令可以快速定位文件路徑,locate指令利用事先建立的系統所有文件名稱及路徑的locate數據庫實現快速定位文件。
  • 第一次運行前建立locate數據庫:updatedb
[root@localhost home]# updatedb
[root@localhost home]# locate a.txt
/home/a.txt
/usr/share/crypto-policies/DEFAULT/java.txt
/usr/share/crypto-policies/EMPTY/java.txt
/usr/share/crypto-policies/FIPS/java.txt
/usr/share/crypto-policies/FUTURE/java.txt
/usr/share/crypto-policies/LEGACY/java.txt
/usr/share/doc/python3-unbound/dict_data.txt
  1. grep 過濾查找,管道符,“|”將前一個命令處理結果傳遞給後面命令處理。
  • grep [選項] 查找內容 源文件
  • -n 匹配行號及內容
[root@localhost home]# grep -n hello a.txt 
4:hello
  • -i 不區分大小寫
[root@localhost home]# cat a.txt | grep -i HELLo
hello
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章