Sunday, August 12, 2012

How to recursively delete directory or file in Ubuntu

Recursively deleting a file which ends in specific file type or deleting a directory which has a specific name is major requirement in sometimes.For a example when you creating patches or providing directories commit,you should clear all .svn directories and other unnecessary files.This will become a headache for if you going yo delete those files or directories one by one.Here is the easy way of doing it.

Deleting a file recursively with user permission
  • find . -type f -name "*.iml" -exec rm -i {} \;
Delete all files which ends with  ".iml" extension recursively with asking the user permission to delete each file.With the "-i" option this allow user to decide whether which file is to delete and which file not to delete each time.


Deleting a file recursively without user permission
  • find . -type f -name "*.iml" -exec rm -f {} \;
Delete all files which ends with  ".iml" recursively at once.

Deleting a directory recursively without user permission
  • find -type d -name '.svn' -exec rm -rfv {} \;
Delete all directories which ends with  ".svn" recursively at once