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 wrote the following function in my .bashrc for use instead of rm * :

function re()
   cp . -R /home/glset/ritwik/trash/
   rm *

It works .. but it is very slow. Even for small files it takes too long to execute. It is always faster to just fire the two commands one after the other which defeats the purpose of the function in the first place. Am I doing something wrong here ? What makes it take longer ?

share|improve this question
There is a minor strangeness there: you cp recursively, but not rm recursively. Are you sure that is what you want? – manatwork Jun 3 '13 at 6:51
What he really wanted to do was cp * /path/to/trash/ – darnir Jun 3 '13 at 6:57
Any particular reason to copy the files and then remove them in stead of removing them. You could get into trouble doing things this way if this is done on the same filesystem and you are running low on disc-space. (It would be faster in that case as well, but it doesn't explain why your function is slow). – Anthon Jun 3 '13 at 7:01
Still one more vote for mv instead. – tripleee Jun 3 '13 at 7:06
You can check if the trash command from the trash-cli package might be useful for you. – Marco Jun 3 '13 at 8:43

Running the function or running the two commands separately does not make any measurable difference in execution time.

My guess would be that you ran the function, found that it was slow, then tried the commands separately.

If you did that, then it's likely that the first time, the data was not present in the disk cache, so what you measured was the time to load the data from the disk. The second time, the data was already in the disk cache (because you had just accessed it), so you measured the time to copy the data around in memory.

To do proper benchmarks, you need to start all measurements in the same conditions: either you know that all the data is in the cache, or you know that all the data has to be loaded from the disk.

Copying the data and then removing the original is a really weird way of doing this. Run mv instead! It's instantaneous if you've moving the files inside the same filesystem.

Furthermore, rm * is a very unusual command. If you don't need a directory anymore, remove the directory: rm -r somedir or mv somedir ~/trash/.

share|improve this answer

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.