33

Using rm -rf LargeDirectory to delete a large directory can take a large amount of time to complete depending on the size of the directory.

Is it possible to get a status update or somehow monitor the progress of this deletion to give a rough estimate as to where along in the process the command is?

2
  • 9
    Try watch -n 5 du -s LargeDirectory. Watch as it goes to zero. Jan 13 '16 at 22:04
  • @MarkPlotnick: on MacOS, have to install it with brew install watch, or see here for instructions.
    – smci
    Jun 1 '19 at 3:35
32

from

man rm 

use the -v option:

-v, --verbose
explain what is being done
2
  • 10
    that’s not progress though. how does “now deleting foo/bar” help you determine how far the complete thing is? May 23 '16 at 13:03
  • @flyingsheep believe it removes everything in alphabetical order, at least in OSX it does, so it does help in some way..
    – Tim Baas
    May 11 '17 at 15:22
19

I see the question is old. I want to share what it works for me to maybe help some else.

I get the progress bar using pv command line Pipe Viewer

This is the command

rm -rv DIR_OR_FILE_NAME | pv -l -s $( du -a DIR_OR_FILE_NAME | wc -l ) > /dev/null

If you need root permissions for the dir or file to delete,

sudo rm -rv DIR_OR_FILE_NAME | pv -l -s $( sudo du -a DIR_OR_FILE_NAME | wc -l ) > /dev/null
  • rm -rv: -r to recursively remove DIRs and files. -v verbose it lists all the files and directories that is removing.

  • pv -l -s: -l to count lines instead of bytes. -s set the total lines to be removed.

  • $( du -a <dir_or_file> | wc -l ): du -a returns a list all files and directories from the dir specified. wc -l returns the count of lines outputted by du -a.

  • > /dev/null: send the output of rm -rv to nowhere.

2
  • Good idea.  This may give an incorrect file/directory count if any names contain newlines; find {dir} -printf . | wc -c would be safer (but -printf is a GNU extension).
    – Scott
    Mar 12 '18 at 19:38
  • This actually is what I was looking for, thank you. Other comments left something lacking.
    – Hellreaver
    Aug 30 '19 at 8:03
5

You can view the progress of any currently running commands with Coreutils Progress Viewer(cv). It isn't like issuing a single command, but you can see the progress with it.

example of CV being used

I'm sure someone can come up with an alias to run this with the command. It also works with cp, mv, dd, tar, gzip/gunzip, cat, etc.. More details about it can be found at

gitthub Xfennec/progress

3
  • 3
    Since progress (as "cv" is now known) tracks open files and rm does not open the files it deletes, this may not actually be very useful.
    – dhag
    Apr 6 '17 at 16:40
  • 2
    @dhag Your right, I thought that this would work for rm. Now I'm debating whether to remove the answer. hmm Apr 7 '17 at 19:29
  • @Ashitakalax It's a bit off-topic, but how to get this prompt that you're using? Looks really cool.
    – zupazt3
    Jan 30 '20 at 14:12
2
rm * & watch 'ls -1 | wc -l'

It removes all files and watch remaining number of files (in current directory)

rm * & watch 'du -h'

it removes all files and watch remaining directory size (in current directory)

You can customize 'rm' command, e.g. 'rm -rf *', removing without confirmation all files/directories recursively (in current directory)

2
  • rm doesn't write to stdout, and watch doesn't read from stdin, so the pipe between them is pointless. If you want to run them at the same time try rm -f * & watch 'ls | wc -l' or consider rm -v *
    – roaima
    Mar 1 '20 at 18:56
  • hmm, okay. Thanks Mar 1 '20 at 19:58
1

Cross-posting from https://github.com/tqdm/tqdm/issues/991, if you have tqdm installed (snap install tqdm, conda install tqdm, pip3 install tqdm, etc) then

rm -rfv LargeDirectory | tqdm --total $(du -a LargeDirectory | wc -l) >/dev/null
0

If the directory to be removed has a very large number of files, du command might take a long time to compute the size of remaining files.

If you have a general sense of how much space the files take up or how much free space there should be after deleting the files, then as an alternative, while the rm command is running, in a separate terminal session/window, try watching how much free-space is left/used on the HDD.

For example:

Run watch df -h (all devices) or watch df -h /dev/path/to/disk (specific HDD)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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