nerdexam
LPI

010-160 · Question #39

A directory contains the following three files: texts 1.txt texts 2.txt texts 3.csv Which command copies the two files ending in .txt to the /tmp/ directory?

The correct answer is B. cp *.txt /tmp/. The wildcard matches any sequence of characters including spaces, making .txt the correct glob to copy all .txt files regardless of how long the base filename is.

The Power of the Command Line

Question

A directory contains the following three files: texts 1.txt texts 2.txt texts 3.csv Which command copies the two files ending in .txt to the /tmp/ directory?

Options

  • Acp ??.txt /tmp/
  • Bcp *.txt /tmp/
  • Ccp .\txt /tmp/
  • Dcp ?.txt /tmp/
  • Ecp $?.txt /tmp/

How the community answered

(26 responses)
  • A
    4% (1)
  • B
    92% (24)
  • D
    4% (1)

Why each option

The * wildcard matches any sequence of characters including spaces, making *.txt the correct glob to copy all .txt files regardless of how long the base filename is.

Acp ??.txt /tmp/

The ?? wildcard matches exactly two characters before .txt, but the base names 'texts 1' and 'texts 2' are each seven characters long, so no files would match.

Bcp *.txt /tmp/Correct

The * glob pattern matches zero or more of any characters, including spaces, so *.txt matches both 'texts 1.txt' and 'texts 2.txt' while automatically excluding 'texts 3.csv' because that filename does not end with the .txt extension.

Ccp .\txt /tmp/

.\txt is not valid Linux glob syntax - the backslash is an escape character and this pattern matches no standard filenames.

Dcp ?.txt /tmp/

The ? wildcard matches exactly one character before .txt, but each file's base name is seven characters, so no files would match.

Ecp $?.txt /tmp/

$? is a special shell variable holding the exit status of the last command and expands to an integer, not a filename glob pattern.

Concept tested: Linux shell glob wildcard pattern matching for file copy

Source: https://www.gnu.org/software/bash/manual/bash.html#Filename-Expansion

Topics

#glob patterns#wildcards#cp command#file selection

Community Discussion

7
Samuel O.Samuel O.Apr 20, 2026

B is your answer. The asterisk is a wildcard that matches any string of characters, including none at all, so *.txt expands to every filename in the current directory that ends in .txt regardless of what comes before that extension. In this directory that nets you "texts 1.txt" and "texts 2.txt" and nothing else, which is exactly what the question asks for. The other options with question marks only match a single character per mark, so ?.txt would need the filename to be exactly one character before the dot, and ??.txt would need exactly two, neither of which fits "texts 1" or "texts 2".

22
Ingrid P.Ingrid P.Apr 14, 2026

I initially flagged A as a candidate because the question feels like it wants you to match a pattern with a fixed character count, and ? looks precise. What snapped me out of it is that "texts 1" is seven characters before the extension, so ? and ?? both fall way short, and only * covers an arbitrary-length match, which is exactly what B gives you.

1
Fatima Z.Fatima Z.Apr 14, 2026

Exactly right, and the hook I use to never mix them up is "Question mark, one question, one character" versus "Star means Start anywhere and go as FAR as you like," so the moment you see a name longer than two or three characters, that star is your only friend.

0
Ola B.Ola B.Apr 28, 2026

B is right, the asterisk matches any number of characters in a filename.

0
Fatima Z.Fatima Z.Apr 30, 2026

Right on, Ola, and just pin this hook to it: STAR stands for Stretch To Any Range of characters including zero, so you never blank on whether "any number" covers the empty case, because it absolutely does.

0
Fatima Z.Fatima Z.Apr 24, 2026

Think STAR GLOB, people: the asterisk is your wildcard STAR that matches ZERO or more characters, so star-dot-txt grabs every filename that ends in .txt no matter how long the name is, which is exactly what B does. The question mark in option A matches exactly ONE character, so it would only grab files like "a.txt" not "texts 1.txt" which has way more than one character before the dot. Option D with a single question mark has the same one-character trap, and E with the dollar sign is pulling from a shell variable, not a glob at all. Here is my genuine question though: if the files were named t1.txt and t2.txt instead, would option A suddenly become correct too, and would both A and B work at the same time?

-1
Samuel O.Samuel O.Apr 25, 2026

Yes, A would also match t1.txt and t2.txt since the question mark covers exactly that one character before the dot, so both A and B would work for that specific set, though B stays the safer catch-all habit to build going into your exam.

0
Full 010-160 Practice