Finding and deleting files in Shell

A quick mini wiki of my frequency used options for find files on Shell.

  • Find files containing a string in filenames, e.g.,
    find ./src/ -name ".cxx"
    This finds all files of suffix .cxx under path ./src/, which is a folder on current Path.
  • Find files containing a string in filenames and delete them, e.g.,
    find . -mindepth 1 -name '.*' -delete
  • Find folders containing a string in filenames and delete them, e.g.,
    find .  -name "CVS" -exec rm -rf {} \;
    Please note the direction of slash in the line above. It's backslash, not forward slash. You can use the -exec option to do everything you wanna do on the shell.

No comments: