Linux error find:paths must precede expression solution

Source: Internet
Author: User


When you perform the find./-mtime +30-type f-name *.php on the server today, the following error is reported:

Find:paths must precede expression

Usage:find [-h] [-l] [p] [path ...] [Expression]
And then I looked it up on the Internet, the results of a search, presumably so: multiple files to find when the need to add single quotes, has been used in double quotes, did not expect to find more than a single quote when the file. Well, another trick, after the revision:

Find./-mtime +30-type f-name ' *.php '

After this implementation, there is no more error, a small problem is resolved.

Example Description:

# Enter the TMP directory to create a new 4 text file
# cd/tmp
# Touch {1,2,3,4}.txt
# Find. -name *.txt
Find:paths must precede expression:2.txt

This hint occurs because the asterisk is expanded to all the files in the current directory, and this is certainly an error. Look at this and you know:

# echo *
1.txt 2.txt 3.txt 4.txt
# echo ' * '
*
# echo \*
*

If you want the asterisk to not be expanded, you need parentheses or a backslash escape, and we know how to find it.

# Find. -name ' *.txt '
Find. -name ' *.txt '
./4.txt
./2.txt
./3.txt
./1.txt

#或者使用反斜杠

Find. -name \*.txt
./4.txt
./2.txt
./3.txt
./1.txt

All right, that's it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.