21

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?

  • 4
    Try watch -n 5 du -s LargeDirectory. Watch as it goes to zero. – Mark Plotnick 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
22

from

man rm 

use the -v option:

-v, --verbose
explain what is being done
| improve this answer | |
  • 5
    that’s not progress though. how does “now deleting foo/bar” help you determine how far the complete thing is? – flying sheep 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
10

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.

| improve this answer | |
  • 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
3

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

| improve this answer | |
  • 2
    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 – Ashitakalax 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 at 14:12
0
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)

| improve this answer | |
  • 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 at 18:56
  • hmm, okay. Thanks – Samuel Granato Mar 1 at 19:58

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.