LFCS practice question 13 of 35
A user accidentally created the subdirectory \dir in his home directory. Which of the following commands will remove that directory?
Full set: 260 questionsThe backslash (\) is a special character in the shell that acts as an escape character. To create or reference a file or directory name containing a literal backslash, that backslash must be escaped or quoted. In this case, the directory is named \dir. The command rmdir ~/\\dir correctly targets this directory. The ~ is expanded by the shell to the user's home directory path, and the \\ sequence is interpreted as a single, literal backslash, correctly forming the path to ~/\dir.
A. rmdir '~/\dir' fails because single quotes prevent the shell from expanding the tilde (~) to the home directory path.
B. rmdir "~/\dir" fails because inside double quotes, \d is interpreted simply as d, targeting the wrong directory (~/dir).
C. rmdir ~/'dir' targets a directory named dir, not \dir, as the backslash is not included within the quotes.
D. rmdir ~/\dir fails because the unquoted \d is interpreted by the shell as just d, targeting the wrong directory (~/dir).
1. GNU Bash Reference Manual, Section 3.1.2.1 "Escape Character": "A non-quoted backslash ‘\’ is the escape character. It preserves the literal value of the next character that follows...". This explains why \\ is needed to represent a literal \.
2. Sobell, M. G. (2017). A Practical Guide to Linux Commands, Editors, and Shell Programming (4th ed.). Pearson. Chapter 4, "The Bourne Again Shell," explains shell metacharacters and the use of the backslash for escaping.
3. MIT OpenCourseWare, 6.005 Software Construction, "Reading 1: The Shell". This reading covers shell basics, including special characters and the need for quoting or escaping them in filenames.
Keep practicing
Take the free LFCS practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other LFCS practice questions
- Question 1Which of the following commands should be added to /etc/bash_profile in order to change t…
- Question 2Which of the following commands reboots the system when using SysV init? (Choose TWO corr…
- Question 3Which of the following tasks can be accomplished using the command date? (Choose TWO corr…
- Question 4Which of the following environment variables overrides or extends the list of directories…
- Question 5Which of the following are syslog facilities? (Choose TWO correct answers.)
- Question 6Which of the following programs uses the hosts.allow file to perform its main task of che…
