Lets see how we can search specific files or directory which was created “N” days before and delete.
For example find files older than 60 days,
Replace the ls
with -delete
to remove files. Be careful, as you might end up deleting important files. Always keep backups. Always run -ls
option first to check about files.
You have been warned.
How to ask for confirm before deleting
Explanation
find
: Find command/path/to/dir/
: Directory path to search-type f
: Only works on files. (the-type d
option only works on dirs)-mtime +60
: Select file with modification time older than 60 days-exec /bin/rm -i {} \;
: Delete file with confirmation-delete
– Delete file-ls
: list file
© 2020, Techrunnr. All rights reserved.