Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What does the question mark in this command mean?

find . –type d –name "?d*" –print

I tried to to run it without it but didn't notice any change.

share|improve this question
6  
That is not regular expression, it is shell pattern. (See Find and regex for similar confusion.) –  manatwork Mar 27 '13 at 17:48
    
Your command contains special characters (“–) rather than regular double-quotes and hyphens ("-). Which ones are you actually using on the command line? If the latter, please edit your post to correct. –  depquid Mar 27 '13 at 18:23
    
The specific term for this is called globbing. –  bahamat Mar 31 '13 at 5:25
add comment

3 Answers 3

The question mark matches exactly one character in a filename. So,

find -name "c?t"

will match cat and cot but not coat or ct.

For what it's worth, this is a very common convention for filename matching, and can be used in a variety of command line interface contexts, even Windows' cmd.

Removing the question mark should make a difference unless nothing was matched anyway.

share|improve this answer
add comment

The pattern "?d*" in find . -type d -name "?d*" -print is interpreted by the find (as is correctly stated by depquid), not by the shell, and will match all the directories that have a second character d even if the first character is a .

For example, if there exist the directories .dad, ada and xd, the find command would print

./.dad
./ada
./xd

while the shell command echo ?d* (where the pattern ?d* is interpreted by the shell) would at least print (there would be and the names of any files matching the pattern)

ada xd

On the other hand if there are no directories with a second character d the find would produce no output in contrast to the shell command that would print

?d*
share|improve this answer
add comment

The question mark is identified by the shell as a single character. In this case the name is specified as any directory with the second character of the directory name 'd', followed by any other characters.

find did not output anything because there were no directory names that matched the -name specification.

share|improve this answer
2  
Strictly speaking, the shell isn't doing matching here; find is. This makes a difference if you have file1 and file2 and try find -name file? instead of find -name "file?", the former matched by the shell and the latter by find. –  depquid Mar 27 '13 at 19:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.