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?
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?
To copy files that end with .txt to the /tmp/ directory, the command cp *.txt /tmp/ is the correct command. The asterisk (*) is a wildcard character that matches any number of characters. Therefore, *.txt will match all files in the directory that have a .txt extension, including texts 1.txt and texts 2.txt.
*. txt means all the txt files
B is the correct answer. the "*" is a "wildcard" meaning it looks for anything with .txt at the end.
cp ?.txt /tmp/ would also copy the two .txt files wouldn't it?
No ? = Matches up exactly one character
The correct answer is B! B - "cp *.txt /tmp/" is the command for copying all files ending in ".txt" to the "/tmp/" directory. This is a wildcard match, which means that any file in the current directory with a ".txt" extension will be copied.
Both B and D results in the same solution. Considering both 1.txt and 2.txt has exactly one character before ".txt", the question mark ? in answer D results in matching those two files in the resolution. That being said, the aserisk * in answer B also matches AT LEAST 1 character before ".txt".
As stated before, "*" selects all .txt files, while "?" is for exactly one character such as "1.txt"