Skip to content
GK24
Computer AwarenessEasy

Which Linux command removes a directory only when it is empty?

  1. A.rm
  2. B.rmdir
  3. C.mv
  4. D.mkdir

Correct answer

B. rmdir

Explanation

The correct answer is B, rmdir. The command rmdir deletes a directory only if nothing is left inside it and prints an error such as directory not empty otherwise, which makes it a safe way to clear away empty folders. Option A is wrong because rm deletes files, and with the recursive option it deletes a directory together with everything it contains, which is why it is treated with care on a live system. Option C is wrong because mv moves a file or a directory to another place and is also the way a file is renamed in Linux, the work done by both MOVE and REN in MS-DOS. Option D is wrong because mkdir creates a directory rather than removing one. The MS-DOS counterpart of rmdir is RD, and of rm is DEL, while DELTREE in MS-DOS does the work of a recursive rm.

Read the full article: MS-DOS and Linux Commands: Internal, External and Shell

View all
Q5.Computer AwarenessMedium

In Linux, the command chmod 777 on a file gives which set of permissions?

  1. A.Read and write to the owner only
  2. B.Read, write and execute to the owner, the group and others
  3. C.Read and execute to everyone, write to nobody
  4. D.Execute to the owner, read to the group, nothing to others
Show answer
Correct answer: B. Read, write and execute to the owner, the group and others

In the numeric form of chmod each of the three digits stands for one set of users, in the order owner, group and others, and each digit is the sum of read as 4, write as 2 and execute as 1.