Linux下find一次查找多個指定類型文件,指定文件或者排除某類文件,在 GREP 中匹配多個關鍵 批量修改文件名等


http://blog.sina.com.cn/s/blog_62e7fe670101dg9d.html

linux下二進制文件查找:

strings 0000.ts | grep -o "T"  | wc -l

 

grep _initcall_.*1$ ./aa > a1

 2982  find . -regex '.*\.c|.*\.cxx|.*\.cpp|.*\.h'
 2983  find . -regex '.*\.c\|.*\.cxx\|.*\.cpp\|.*\.h'
 2984  find . -regex '.*\.c\|.*\.cxx\|.*\.cpp\|.*\.h' | xargs grep "malloc" -rn
 2985  find . -regex '.*\.c\|.*\.cxx\|.*\.cpp\|.*\.h' | xargs grep "malloc" -rn > mem.malloc
 2986  vim mem.malloc
 2987  find . -regex '.*\.c\|.*\.cxx\|.*\.cpp\|.*\.h' | xargs grep "free" -rn > mem.free
 2988  find . -regex '.*\.c\|.*\.cxx\|.*\.cpp\|.*\.h' | xargs grep "strdup" -rn > mem.strdup
 2989  find . -regex '.*\.c\|.*\.cxx\|.*\.cpp\|.*\.h' | xargs grep "realloc" -rn > mem.realloc
 2990  find . -regex '.*\.c\|.*\.cxx\|.*\.cpp\|.*\.h' | xargs grep "calloc" -rn > mem.calloc
 2991  find . -regex '.*\.c\|.*\.cxx\|.*\.cpp\|.*\.h' | xargs grep "new" -rn > mem.new
 2992  find . -regex '.*\.c\|.*\.cxx\|.*\.cpp\|.*\.h' | xargs grep "delete" -rn > mem.delete 

 

批量修改文件名

rename 's/\.pkt/\.aac/' *

http://any2sky.blog.163.com/blog/static/468518032010914101851175/

 

將通過find命令找到的文件拷貝到一個新的目錄中:

cp `find  . -name "*pcm*.[c,h]"` tmp/ -rf

方法一    www.2cto.com  
命令如下:
find src_dir -name "access.log.2011102[2-6]*" -exec cp {} dst_dir \;
 
拷貝文件到遠程主機上的目標目錄的命令:
find src_dir -name "access.log.2011102[2-6]*" -exec scp {} 用戶名@主機ip:dst_dir \;
 
方法二
find src_dir -name "access.log.2011102[2-6]*" |xargs -i cp {} dst_dir
find src_dir -name "access.log.2011102[2-6]*" |xargs -I {} cp {} dst_dir
 
拷貝文件到遠程主機上的目標目錄的命令:
find src_dir -name "access.log.2011102[2-6]*" |xargs -i scp {} 用戶名@主機ip:dst_dir
find src_dir -name "access.log.2011102[2-6]*" |xargs -I {} scp {} 用戶名@主機ip:dst_dir
 
src_dir 源目錄
dst_dir 目標目錄

access.log.2011102[2-6]* 文件名的正則表達式,獲取文件的條件

Linux下find一次查找多個指定文件或者排除某類文件,在 GREP 中匹配多個關鍵字的方法
(1)Linux下find一次查找多個指定文件:
查找a.html和b.html

  1. find . -name "a.html"  -name "b.html"  


find . -regex '.*\.txt\|.*\.doc\|.*\.mp3'

  1. find . -regex '.*\.txt\|.*\.doc\|.*\.mp3'  
  2. ./a.txt  
  3. ./a.doc  
  4. ./a.mp3  


(2)排除某些文件類型:
排除目錄下所有以html結尾的文件:

  1. find . -type f ! -name "*.html"    

 

  1. find . -type f ! -name "*.html"       
  2. ./ge.bak.02.09  
  3. ./ge.html.changed.by.jack  
  4. ./a.txt  
  5. ./a.doc  
  6. ./a.mp3  


(3)排除多種文件類型的示例:

  1. find . -type f ! -name "*.html" -type  f ! -name "*.php" -type  f ! -name "*.svn-base"  -type  f ! -name "*.js"  -type  f ! -name "*.gif"  -type  f ! -name "*.png"  -type  f ! -name "*.cpp"  -type  f ! -name "*.h"  -type  f ! -name "*.o"  -type  f ! -name "*.jpg"  -type  f ! -name "*.so"  -type  f ! -name "*.bak"  -type  f ! -name "*.log"   


(3)在 GREP 中匹配多個關鍵字的方法:
grep查找多個數字的文件:
-r 遞歸,-E:正則  -l:只顯示文件名

  1. root@116.255.139.240:~/a# grep -r -E '0341028|100081|10086|10001' *  
  2. a.txt:100081  
  3. b.txt:10086  
  4. c/cc.txt:0341028  
  5. c/cc.txt:100081  
  6. c/cc.txt:10086  
  7. c/cc.txt:10001  
  8. c.txt:10001  
  9. d.txt:0341028  

 

  1. grep -r  -E -l '0341028|100081|10086|10001' *     
  2. a.txt  
  3. b.txt  
  4. c/cc.txt  
  5. c.txt  
  6. d.txt  


多種類型文件示例:

  1. find . -name "*.html" -o -name "*.js"|xargs grep -r "BusiTree"   



用Awk:

  1. find . -name "*.php"|awk '{print "cat " $0 " |grep -H dbsys.mxxxx.justwinit.cn"}'|sh  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM