Find and Remove Files from Shell Prompt in Linux

Posted on December 7, 2016 at 11:08 am

How do I find and delete files under Linux / UNIX?

Remove all error.log files from a folder and its subfolders:

find /var/www/ -type f -name "error.log" -exec rm -rf {} \;

Remove all access.log files from a folder and its subfolders:

find /var/www/ -type f -name "access.log" -exec rm -rf {} \;

Remove all *.log files from a folder and its subfolders:

find /var/www/ -type f -name "*.log" -exec rm -rf {} \;

Ask a confirmation (y\n) to delete all the files found:

find /var/www/ -type f -name "*.log" -exec rm -i {} \;

Recursively search and delete directories:

find /var/www/ -type d -name "directory-name" -exec rm -rf {} \;

Stay Updated

Other Posts

Updated Posts