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?


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

| improve this answer | |
  • 9
    I wouldn't speak of "echo commands". Most programs aren't bash scripts so they do not call echo. The problem is that they are writing to stdout (or stderr), in other words, they are performing I/O operations, which require time (I/O is costly) and they also require system calls (which means more context switches and hence more cache miss etc.). – Bakuriu Oct 9 '14 at 18:25
  • 23
    The main problem with writing to stdout is the actual rendering of that content; if you redirect stdout to a file, or /dev/null, performance is not nearly so hampered as displaying text on a terminal emulator. – Jacob Krall Oct 9 '14 at 18:48
  • As you can see from the graph, the difference in time is negligible if you are talking about response time from a human's point of view. Thus, if you are worried about efficiency for a person watching the command, it's not relevant. It's only relevant for huge numbers of files or for many repeated runs where computer time is precious (e.g. a busy web server or an ancient computer). – Paddy Landau Oct 14 '14 at 11:07
  • The most impact, and probably the only case where it would really matter, is when you run the command on a remote machine via SSH. Verbose logging may easily generate tens of megabytes of traffic which would have to be transmitted from the host to your console. I once experienced a speedup in order of 10x after removing excessive console logging from a script which I ran via SSH. – Sergey Oct 14 '14 at 22:35

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
| improve this answer | |
  • 11
    This doesn't really answer the question. A difference of 1 ms between single runs of each command could be caused by a lot of factors. Also not clear if you omitted the -v output or the directory was empty. – user234837 Oct 9 '14 at 21:02
  • Not to mention the slow down isn't from the extra executed instructions, but from the process of writing it to a file or the terminal. time' pretty much redirects the output to /dev/null'. – Cole Johnson Jul 21 '16 at 3:25

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.