nerdexam
LPI

010-160 · Question #84

Which of the following commands output the content of the file Texts 2.txt? (Choose two.)

The correct answer is A. cat 'Texts 2.txt' E. cat Texts\ 2.txt. When a filename contains spaces, the shell requires quoting or escaping so it is treated as a single argument rather than multiple arguments.

The Power of the Command Line

Question

Which of the following commands output the content of the file Texts 2.txt? (Choose two.)

Options

  • Acat 'Texts 2.txt'
  • Bcat -- Texts 2.txt
  • Ccat [Texts 2.txt]
  • Dcat 'Texts| 2.txt'
  • Ecat Texts\ 2.txt

How the community answered

(23 responses)
  • A
    91% (21)
  • B
    4% (1)
  • C
    4% (1)

Why each option

When a filename contains spaces, the shell requires quoting or escaping so it is treated as a single argument rather than multiple arguments.

Acat 'Texts 2.txt'Correct

Enclosing the filename in single quotes (`'Texts 2.txt'`) passes the entire string including the space as one argument to `cat`, correctly identifying the file.

Bcat -- Texts 2.txt

The double-dash `--` signals the end of options but does not quote or join arguments, so `cat` receives two separate arguments - 'Texts' and '2.txt' - and will report errors for both.

Ccat [Texts 2.txt]

Square brackets in the shell are glob/pattern matching metacharacters, not a quoting mechanism, so `[Texts 2.txt]` would be interpreted as a character class pattern, not the literal filename.

Dcat 'Texts| 2.txt'

Single-quoting preserves every character literally, so `'Texts| 2.txt'` would look for a file whose name contains a pipe character, which does not match the actual filename 'Texts 2.txt'.

Ecat Texts\ 2.txtCorrect

A backslash before the space (`Texts\ 2.txt`) is a shell escape sequence that tells the shell to treat the space as a literal character rather than an argument separator, so `cat` receives the correct single filename.

Concept tested: Shell quoting and escaping spaces in filenames

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

Topics

#cat command#filename quoting#escape characters#special characters

Community Discussion

No community discussion yet for this question.

Full 010-160 Practice