Recursively Remove Files From Folder

A shell script that is used to recursively remove any pattern of files like swap files, thumb.db files, etc, under a given folder and the subfolders under the given folder.


  • Recursively Remove your unwanted files in a fraction of second.
  • It makes easier to find and delete the swap files under the folder and subfolder of the given path.
  • Just copy the code and use it in your command prompt.
  • Fast and simple remove files shell script.


#------------------Script by
#--------------More scripts
echo "Enter Folder Name under which you want to remove files:";
read fname
echo "Enter the pattern to remove (for eg, if swap files give as *~ else if thumbs.db give as Thumbs.db)";
read name1
echo "Total Count of files found on the pattern" $name1;
find $fname -type f -name "$name1" | xargs wc -l
find $fname -type f -name "$name1" -exec rm {} \;
#------------ Script by -------------------------#

  • Release Date - 30-09-2010
  • Get free version without ©copyright link for just $10/-
  • For customization of this script or any script development, mail to


  • Copy the above code and save it with .sh extension
  • Execute the shell script as sh to remove the files recursively.
  • Give the foldername under which you want to delete the files.
  • It will prompt the user to enter the pattern.
  • Specify the pattern for removing. for eg,
  • if you want to remove all swap files under the folder then do specify as "*~".
  • if you want to remove all thumbs.db files under the folder then do specify as "Thumbs.db".
  • Likewise you can also remove all error_log files, etc., recursively.
  • Finally it gives you the total number of files found for the pattern.


Other Scripts

Ask Questions

Ask Question