Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Nov 13 '12 at 7:46

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

add comment

4 Answers

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
add comment

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
add comment

try

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
add comment

Try doing this :

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.