Monday, April 23, 2012

Linux / UNIX: Deleting Files In Many Subdirectories

How do I delete all files (only files and not subdirs) located in /var/pub/ftp/incoming and its subdirectories under Linux or UNIX operating systems?

You can use any one of the following command:
# find /var/pub/ftp/incoming -type f -delete
Your find command may not support -delete option, so use it as follows:
# find /var/pub/ftp/incoming -type f -print0 | xargs -0 -I file rm -f file
OR
# find /var/pub/ftp/incoming -type f -exec rm -f {} \;
You can also select file types. In this example, delete all *.exe files, enter:
# find /var/pub/ftp/incoming -type f -iname "*.exe" -exec rm -f {} \;

No comments:

Post a Comment