I'm trying to run an auto-delete script to free up space on a remote server.
The command I'm thinking to use is:
find . -atime 30 -mtime 30 -type f -delete
What I want is to also capture which files were successfully deleted and which failed because of access issue. How should I do this? I think this command below might take care of the failures only, but I'm not sure.
find . -atime 30 -mtime 30 -type f -delete 2>failed_deletions.txt
CodePudding user response:
find
out of the box does not print the files it processes. If you want to list the files, add a -print
or -ls
before the -delete
.
This obviously prints all the files it processes, including the ones it fails to delete for whatever reason.
Redirecting standard output to a different file should be trivial to discover; command >stderr 2>stdout
CodePudding user response:
Less performant, but should do what you wanted:
find . -atime 30 -mtime 30 -type f -exec rm -v {} \; >successful.txt 2>failed.txt