45

In this question: How to remove all files and subdirectories in a directory WITHOUT deleting the directory in bash? it is asked how to delete all file in a folder, and not the folder itself.

Matts exelent answer includes the use of the -v flag to the 'rm' command.

rm -rfv dontDeleteMe && mkdir dontDeleteMe

The command I left with was the one above. Certainly useful indeed, but does the -v flag in 'rm' and/or in general slow down tasks done through the command line?

I have a folder with .txt-files (about 100.000 of them) that I have created, deleted and recreated for myself a few times now. Some times with rm, some times in the filebrowser, and I get the feeling it's even slower to use the rm-command as show above. Does the -v flag have anything to do with this?

Eiriks
  • 585

2 Answers2

50

Yes, the -v flag slows down the command.

Most, if not all softwares(or commands) would check if a flag is provided, and then execute a bunch of code related to the flag. In case of the -v flag, they would likely execute a bunch of output commands(like echo or printf), which they rather would have skipped without the flag.

This means more instruction cycles for the processor and thus more execution time.

It is better if you don't use -v flag if you are not going to read/need the messages.

On the other hand, the CLI would/should be faster than GUI, assuming that you don't include time required to type the commands and pressing the Enter key.

From this blog of superuser this image explains the slowness very well

enter image description here

For the specific command in question, the results of the time command are

//with -v
real    0m8.753s
user    0m0.816s
sys     0m2.036s

//without -v
real    0m1.282s
user    0m0.124s
sys     0m1.092s

this was done with the directory containing 100000 empty files

7

Why not find out yourself: use time.

$ time rm -rfv dontDeleteMe && mkdir dontDeleteMe
real    0m0.003s
user    0m0.001s
sys     0m0.002s

$ time rm -rf dontDeleteMe && mkdir dontDeleteMe
real    0m0.002s
user    0m0.001s
sys     0m0.001s
sethmuss
  • 79
  • 1