Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 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
up vote 48 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
This is rather difficult with a large number of files. – Cory Klein Feb 7 '11 at 20:13
yes n | rm -i #comment to meet minimum comment length – Joshua May 4 at 18:46

Your Answer


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.