I want to clear some pdf files in the server /tmp directory, about 10,000 files, when I execute the command
find /tmp -maxdepth 1 -mtime 30 -name *.pdf
An error occurred:
find : paths must precede expression Usage: find [-H] [-L] [-P] [path...] [expression]
Then I checked it on the Internet, and I found an article. It probably said: When searching for multiple files, you need to add single quotation marks. Double quotation marks have always been used. I didn’t expect to use single quotation marks when looking for multiple files. Well, I learned another trick. After modification:
find ./ -mtime +30 -type f -name’*.php’
so that no more errors will be reported after execution, and a small problem will be solved.
Example explanation:
# Enter the tmp directory Create 4 new text files
# cd /tmp
# touch {1,2,3,4}.txt
# find .-name *.txt
find: paths must precede expression: 2.txt
This prompt appears because the asterisk is expanded to For all files in the current directory, such matching will of course be wrong. Look at this to know:
# echo *
1.txt 2.txt 3.txt 4.txt
# echo’*’
*
# echo \*
*
If you want the asterisk not to be expanded, you need to add parentheses or backslashes to escape , Knowing these we will know how to find
# find. -Name’*.txt’
find.
-Name ‘*.txt’ ./4.txt
./2.txt
./3.txt
./1.txt #Or
use backslash to
find .-name \*.txt
./4.txt
./2.txt
./3.txt
./1.txt
Read More:
- [Solved] find command error: paths must precede expression
- [Solved] Find command error: find: missing “- exec” parameter solution
- [Solved] sed -i error: sed: -e expression #1, char 44: invalid reference \1 on `s’ command’s RHS
- [Solved] Cannot find command ‘git‘ – do you have ‘git‘ installed and in your PATH?
- How to Solve Linux Error: -bash: unzip: command not found
- [Solved] Sed Failed to Reference Variable error: extra characters after command
- [Solved] Ubuntu tab Error: _complete:96: bad math expression: operand expected at end of string
- [Solved] /usr/bin/ld: cannot find crti.o: No such file or directory & /usr/bin/ld: cannot find -lc
- Windows command execution bypass
- Grep: How to Find All the Files Containing a String in Linux
- Notes on Linux SCP command using specific port
- VMware: vmw_ ioctl_ Command error invalid parameter [How to Solve]
- How to Use Apt get Command Under Mac OSX
- MAC Adb Shell Error: -bash: adb: command not found, adb
- Error report when executing ifconfig under centos7
- -bash: sqlplus: command not found [How to Solve]
- Error report after installing Oracle GoldenGate monitor agent oggmon-20603
- [Solved] Error report of introducing Vue into ecarts GL
- [Solved] Fluent error: invalid command [initialize-flow
- [Solved] error adding symbols: DSO missing from command line