Tuesday, May 08, 2012

Super duper command: find


  • Find files with filename containing WORD
    find -type f -name \*WORDS\*  
  • Find files by name in case-sensitive way, e.g. containing word or Word...
    find -type f -iname \*word\*
  • Find files with name containing "word", "Word" etc., but not "WORD"
    find -type f -iname \*word\* -not -name \*WORD\*
  • Unzip all *.tar.gz files
    find -type f -name \*.gz -exec tar -zxvf {} \;
  • Use pipe in find command
    find ~/scratch/RNAseq/ -type f -name clean.fa -printf "a=\`echo %p | cut -f6- -d'/' | sed 's/\//./g'\`; cp %p \$a \n" | sh
    # copy /home/dongx/scratch/RNAseq/****/xxxx/clean.fa to ****.xxxx.clean.fa

References:

  • http://www.linux.ie/newusers/beginners-linux-guide/find.php
  • http://stackoverflow.com/questions/307015/how-do-i-include-a-pipe-in-my-linux-find-exec-command



No comments:

Post a Comment