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.
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)- A3% (1)
- B3% (1)
- C11% (4)
- D6% (2)
- E77% (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.
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.
Double quotes also suppress tilde expansion in bash, so ~bob remains unexpanded and the path cannot resolve to the correct directory.
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.
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.
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
Community Discussion
No community discussion yet for this question.