Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to see what files will be deleted when performing an 'rm' in linux. Most commands seem to have a dry run option to show just such information, but I can't seem to find such an option for rm. Is this even possible?

share|improve this question

2 Answers 2

up vote 28 down vote accepted

Say you want to run:

rm *.txt

You can just run:

echo rm *.txt

or even just:

echo *.txt

to see what files rm would delete, because it's the shell expanding the *.txt, not rm.

The only time this won't help you is for rm -r.

If you want to remove files and directories recursively, then you could use find instead of rm -r, e.g.

find . -name "*.txt" -print

then if it does what you want, change the -print to -delete:

find . -name "*.txt" -delete
share|improve this answer
    
find is a good choice IMO. And if you want a graphical presentation use tree. –  noisebleed Jul 25 '12 at 9:49
    
Almost perfect. find . -name "*.txt" -delete doesn't seem to be recursive tho. Removed all the files, but didn't remove directories that were listed in -print –  Oscar Godson Jul 21 '13 at 9:17

You can say:

rm -i

to run it in interactive mode, so rm will prompt you to confirm whether each file should be deleted. You could just answer no to each file to see which ones would be affected.

share|improve this answer
3  
This is rather difficult with a large number of files. –  Cory Klein Feb 7 '11 at 20:13

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.