nerdexam
Linux_Foundation

LFCS · Question #730

A user accidentally created the subdirectory \dir in his home directory. Which of the following commands will remove that directory?

The correct answer is E. rmdir ~/\\dir. To remove a directory whose name contains a literal backslash, the backslash character must be escaped with another backslash to prevent the shell from interpreting it as an escape sequence.

Submitted by valeria.br· Apr 18, 2026Essential Commands

Question

A user accidentally created the subdirectory \dir in his home directory. Which of the following commands will remove that directory?

Options

  • Armdir '~/\dir'
  • Brmdir "~/\dir"
  • Crmdir ~/'dir'
  • Drmdir ~/\dir
  • Ermdir ~/\dir

How the community answered

(51 responses)
  • A
    6% (3)
  • B
    2% (1)
  • C
    2% (1)
  • D
    12% (6)
  • E
    78% (40)

Why each option

To remove a directory whose name contains a literal backslash, the backslash character must be escaped with another backslash to prevent the shell from interpreting it as an escape sequence.

Armdir '~/\dir'

Single quotes `''` prevent most shell expansions, but the `~` (home directory) expansion usually occurs before quoting. However, `\dir` inside single quotes will treat `\dir` literally as part of the path, which is not correct for removing `\dir` where the first `\` is a literal. The shell needs to see `\\` to interpret `\` as part of the directory name.

Brmdir "~/\dir"

Double quotes `""` suppress some shell expansions but `\` is still an escape character within them. For a literal backslash, it still needs to be escaped as `\\`.

Crmdir ~/'dir'

This command would attempt to remove a directory named `dir` (without a leading backslash) in the home directory, which is not the target.

Drmdir ~/\dir

Without quoting or escaping, the `\` would be interpreted by the shell as an escape character for the 'd', meaning `\dir` would likely be interpreted as `dir`, or result in a syntax error.

Ermdir ~/\\dirCorrect

The backslash (`\`) is an escape character in the shell. To specify a literal backslash in a directory name like `\dir`, the backslash itself must be escaped, resulting in `~/\\dir` for `rmdir` to correctly interpret the path.

Concept tested: Shell escaping special characters

Source: https://www.gnu.org/software/bash/manual/bash.html#Quoting

Topics

#rmdir command#Shell escaping#Special characters#Directory management

Community Discussion

No community discussion yet for this question.

Full LFCS Practice