Linux 查詢指令檔案與檔案字串
Linux 查詢檔案與檔案字串
find: 資料夾->檔案名稱
find -name 'BigSchool.txt'
find -name '*School.txt'
find /home -name 'BigSchool.txt'
grep:
grep -r 'Tom' BigSchool.txt
grep -r 'Hank' *(可省略)
[root@apServer findgrepfile]$ ls
BigSchool.txt LocalSchool.txt SmallSchool.txt university
[root@apServer findgrepfile]$ ls university/
UniversityBigSchool.txt UniversitySmallSchool.txt
[root@apServer findgrepfile]$ find -name 'University*'
./university/UniversityBigSchool.txt
./university/UniversitySmallSchool.txt
[root@apServer findgrepfile]$ find university -name 'University*'
university/UniversityBigSchool.txt
university/UniversitySmallSchool.txt
[root@apServer findgrepfile]$ grep -r 'Amber' *
SmallSchool.txt:student:Amber
[root@apServer findgrepfile]$ grep -r 'Amber' BigSchool.txt
[root@apServer findgrepfile]$ grep -r 'Amber' SmallSchool.txt
student:Amber
[root@apServer findgrepfile]$ find university -name '*School.txt' -exec grep -r -in 'Jerry' {} \;
[root@apServer findgrepfile]$ find university -name '*School.txt' -exec grep -r -in 'Tom' {} \;
[root@apServer findgrepfile]$ find university -name '*School.txt' -exec grep -r -in 'Hank' {} \;
2:student:Hank
ps.-exec參數時必須以\;結尾