Q. Is rm -rf * removes the files in alphabetically?

Simple answer is yes, the files/folders are removed in alphabetic sequence. I ran strace command to support my answer.

I have 4 files in my dir as shown below

surendra@linuxnix.com:~/scripts/temp/temp$ ls -lrt
total 0
-rw-rw-r– 1 surendra surendra 0 Oct 10 23:55 c.txt
-rw-rw-r– 1 surendra surendra 0 Oct 10 23:55 b.txt
-rw-rw-r– 1 surendra surendra 0 Oct 10 23:56 a.txt
-rw-rw-r– 1 surendra surendra 0 Oct 10 23:56 d.txt

When issued rm -rf * along with strace, I can see rm -rf * is converted to rm -rf a.txt b.txt c.txt d.txt irrespective of time stamp they have as shown below.

Strace command output for rm -rf *

surendra@linuxnix.com:~/scripts/temp/temp$ strace rm -rf *

execve(“/bin/rm”, [“rm”, “-rf”, “a.txt”, “b.txt”, “c.txt”, “d.txt”], [/* 43 vars */]) = 0

I have clipped the output of strace command.

From this we can conclude that * always changed to alphabetic sequence for many commands such as rm, cp, mv, find etc.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.