Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using this command: find /var/mydirectory/foo -mmin +720 -exec rm {} \;

Can I make it log the filenames removed to a log?

share|improve this question

migrated from Nov 13 '12 at 7:46

This question came from our site for professional and enthusiast programmers.

up vote 3 down vote accepted

Use the tee command in conjunction with xargs.

find /var/mydirectory/foo -mmin +720 | tee files.log | xargs rm
share|improve this answer

You could always use the --verbose option to rm, unless you want just the literal filenames by themselves.

share|improve this answer
I like this answer... if something goes wrong with unlinking, none of the other methods will reflect that. – Ben Voigt Nov 13 '12 at 0:17
In this case I actually just want the filenames to compare against another log for an issue I'm having. – Dave Stein Nov 13 '12 at 0:21
@DaveStein You could always sed/grep out the filenames from the output of rm -v if you're really concerned that something may have gone wrong and want to make absolutely sure you're only dealing with the files that were deleted. However, that's likely unnecessary and it would be somewhat unclear. The solution with tee will be extremely clear to anybody familiar with the shell. – Tim Pote Nov 13 '12 at 0:26


find /var/mydirectory/foo -mmin +720 | tee file.txt | xargs rm
share|improve this answer
Not whitespace-safe – Kevin Nov 13 '12 at 2:33

Try doing this :

find /var/mydirectory/foo -mmin +720 > file.txt
rm $(< file.txt)
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .