Linuxshell determines whether the file exists

Source: Internet
Author: User
Shell checks whether a file exists or has Permissions #! /Bin/shmyPath & quot;/var/log/httpd/& quot; myFile & quot;/var/log/httpd/access. log & quot; # Here, the-x parameter determines whether $ myPath exists and has executable permissions. if [! -X & quot; $ myPat... shell: determines whether a file exists or has Permissions #! /Bin/sh myPath = "/var/log/httpd/" myFile = "/var/log/httpd/access. log "# Here, the-x parameter determines whether $ myPath exists and has executable permissions. if [! -X "$ myPath"]; then mkdir "$ myPath" fi www.2cto.com # Here, The-d parameter determines whether $ myPath exists if [! -D "$ myPath"]; then mkdir "$ myPath" fi # Here, the-f parameter determines whether $ myFile exists if [! -F "$ myFile"]; then touch "$ myFile" fi # Other parameters include-n, which determines whether a variable has a value if [! -N "$ myVar"]; then echo "$ myVar is empty" exit 0 fi # determine whether two variables are equal if ["$ var1" = "$ var2"]; then echo '$ var1 eq $ var2 'else echo' $ var1 not eq $ var2' fi author sundful
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.