Understanding about the error of the find command in Shell Environment

Source: Internet
Author: User

Article Source: http://zhousir1991.diandian.com/page/4

[Root @ My ~] # Find.-Name *. rpm
/Nessus-4.0.1-es5.i386.rpm


[Root @ My ~] # Find.-Name * .tar.gz
Find: paths must precede expression: recordmydesktop-0.3.8.1.tar.gz
Usage: find [-H] [-L] [-p] [-olevel] [-D help | tree | search | stat | rates | opt | exec] [path...] [expression]


[Root @ My ~] # Find.-Name '* .tar.gz'
/Gtk-recordmydesktop-0.3.8.tar.gz
/Recordmydesktop-0.3.8.1.tar.gz


The above are my problems,Solve the problem after single quotation marks are added: You can find relevant information on the Internet to solve this problem. For copyright issues, please contact me!


In find/-name MySQL *, the-name parameter is not the actual MySQL *, but the shell first parses msyql *. If the file name or directory name starting with MySQL can be found in the current directory, pass the matched file name or directory name as the name parameter to it in the following three cases:
1. If no matching shell exists, pass MySQL * to find;
2. If only one of them is matched, the find command will be executed normally, but the result is incorrect. For example, if the current directory only has one directory or file named mysqla, shell will pass mysqla as the name parameter to find, then run the command;
3. If multiple matches are found, an error is returned. The error message is as follows:
Find: paths must precede expression
Usage: Find [-H] [-L] [-p] [path...] [expression]

That is to say, when multiple files or directories are matched, shell will pass all the matched files or directories as the name parameter to find, which causes the find operation to fail. For example, the current directory has mysqla
In mysqlb, the command line after shell matching is find/-name mysqla mysqlb, so that find cannot be executed normally.

And find/-name "MySQL *", shell will not parse the MySQL * expression, directly pass MySQL * To find, find will be executed normally, and get the desired result.

Conclusion: in the future, we should strive for rigor in Shell usage!



Related Article

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.