nerdexam
CompTIA

LX0-103 · Question #189

Bob accidentally created the subdirectory \bobsdir in his home directory. He tried to remove the subdirectory with the command rmdir \bobsfile only to receive the error: "No such file or directory." W

The correct answer is E. rmdir ~bob/\\bobsdir. The directory name contains a literal backslash character, requiring correct shell escaping to reference it. Only a double backslash in an unquoted context produces the correct path.

GNU and Unix Commands

Question

Bob accidentally created the subdirectory \bobsdir in his home directory. He tried to remove the subdirectory with the command rmdir \bobsfile only to receive the error:

"No such file or directory." Which of the following commands will remove the directory?

Options

  • Armdir '~bob/\bobsdir'
  • Brmdir "~bob/\bobsdir"
  • Crmdir ~bob/'bobsdir'
  • Drmdir ~bob/\bobsdir
  • Ermdir ~bob/\bobsdir

How the community answered

(35 responses)
  • A
    3% (1)
  • B
    3% (1)
  • C
    11% (4)
  • D
    6% (2)
  • E
    77% (27)

Why each option

The directory name contains a literal backslash character, requiring correct shell escaping to reference it. Only a double backslash in an unquoted context produces the correct path.

Armdir '~bob/\bobsdir'

Single quotes prevent tilde expansion entirely, so ~bob is treated as a literal string rather than the home directory path, producing a path that does not exist.

Brmdir "~bob/\bobsdir"

Double quotes also suppress tilde expansion in bash, so ~bob remains unexpanded and the path cannot resolve to the correct directory.

Crmdir ~bob/'bobsdir'

Tilde expands correctly outside quotes, but single-quoting only 'bobsdir' removes the backslash from the name, so the resolved target is bobsdir rather than \bobsdir.

Drmdir ~bob/\bobsdir

In an unquoted context, a single backslash before 'b' acts as an escape character, causing the shell to interpret \b as just 'b', so the path resolves to bobsdir without a leading backslash.

Ermdir ~bob/\\bobsdirCorrect

In an unquoted shell context, tilde (~bob) expands to the home directory path. The double backslash (\\) is interpreted by the shell as a single escaped literal backslash, producing the resolved path /home/bob/\bobsdir, which matches the actual directory name created with the backslash prefix.

Concept tested: Shell quoting and backslash escaping in file paths

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

Topics

#shell escaping#special characters#rmdir#backslash

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice