A command in the Linux shell command to determine if a known suffix name file exists under the directory __linux

Source: Internet
Author: User

Today, there is a problem that needs to be judged whether there is a. c file in the directory. I used the IF [-f *.c], using the-F and wildcard characters to determine if there is a. c file, while Linux always complains "unexpected operator", so under-F, wildcard characters are not available later.

Later, I thought of a soil method, if [-n "' ls *.c '"], which means that if the LS command is executed, it is true, where-n indicates that the following content is not a null value. This sentence is available, you can determine the file exists in the directory, but this is a problem, if the directory does not have a. c file, it will be the error "No such files or directory", so I gave up this method.

A cow in the last QQ group told me, using if LS *.c >/dev/null 2>&1;then, this is a redirection method, ls all the file with. c suffix, if not, redirect standard error to standard output, here 2> &1 means that the standard error is also exported to the standard output. REDIRECT 0-standard output, 1-standard output, 2-standard error, and no such file or directory is a standard error.

Original address: http://www.tonitech.com/71.html


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.