I'm having some trouble while searching files with find command and the way it handles the search.
Let's say I'm currently in the directory /tmp and the directory contains the files: backup-20151219.zip, backup-20151220.zip, backup-20151221.zip.
Then my search command is:
[root@server tmp]# find /tmp -type f -mtime +2 -name backup* -exec rm -f {} \;
And I get the following:
find: paths must precede expression: backup-20151219.zip
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
That's because it matched the backup* regex and used it as the search pattern instead of using it to filter results. That I know.
If I change to another directory which does not contain files beginning with backup*, it shows the expected results.
So, I wanted to know if there is a way to search files using wildcards while being in a directory that may contain matches and show them as results.
*
breaks things. The shell expandsbackup*
to any files it finds in the current directory. Thenfind
will "see" a "bare" filename ...find /tmp -name backup1 backup2 ...
. It's thebackup2
which find complains about. Feel free to copy/paste this back into your answer. – Otheus Dec 21 '15 at 15:08backup*
as a literal if there are no matching files. When the option is set differently,backup*
will expand to the empty string. – Otheus Dec 22 '15 at 22:08