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.zipUsage: 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.I hope I was clear enough. Thanks for any help!
find command match issue
shell;find;quoting;wildcards
In short - yes there is way. You simply have to escape the wildcard characters somehow. There are multiple ways to do this, the method I use most often is to escape the particular wildcards:find . -name backup\* -printOr, simply quote the pattern:find . -name backup* -printOther ways will work just as well - the main point is to somehow prevent the shell from seeing the wild card as a glob expression.