20

I want show all the files that have a .bak extension.

kaykav@ubu2:~/Documents$ ls
cdIndex1-60  met.bak  tem.bak

I type the cmd : $ find . -name *.bak

I'm in the correct Directory for this. I get the following message:

find: paths must precede expression: tem.bak

What does that mean? Man pages are no help.

1

1 Answer 1

27

Try putting it in quotes:

find . -name '*.bak'

When you simply use find . -name *.bak in that directory shell expands it to find . -name tem.bak met.bak (i.e. interprets * as the wildcard)

2
  • thank you for your reply. I'm not sure I comprehend the answer but it works. I thought *.bak means 'all' results that have a .bak ending.
    – kaykav
    Jul 9, 2012 at 0:44
  • 7
    @kaykav When you run find . -name *.bak, the third command-line argument, *.bak, is expanded by the shell before it is passed to find. Shell expansion will convert it to a space-delimited list of all the filenames in the current directory that match it, i.e., all the files whose names consist of zero or more characters (*) followed by .bak. When you enclose *.bak in quotes, that escapes the * wildcard, so the expression is passed unexpanded. You could alternatively use find . -name \*.bak. Jul 9, 2012 at 3:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .