Delete multiple files that contain spaces based on age

I had a problem on a FTP server running Solaris 9 that had tons of old files and many of them had spaces in the names. How do you automate removing the old files (the real concern being the spaces in the filenames)? Most solutions recommend using -print0 in find or xargs -0, neither of which are options in Solaris 9.

This command removes any files older then 2 years old in the current directory:

find . -type f -mtime +730 | while read filename; do rm -f “$filename”; done

1 thought on “Delete multiple files that contain spaces based on age

  1. To remove empty directories quickly (relying on rmdir to not delete directories unless they are empty) that have spaces in them:

    find . -type d | while read foldername; do rmdir “$foldername”; done

    If there are empty folders inside of other folders then you would need to run this multiple times…

Leave a Comment