Shell determines whether a file or folder exists

Source: Internet
Author: User

Tag: Folder file exists and dir file directory parameter is judged

#shell判断文件夹是否存在 # If the folder does not exist, create a folder if [!-D "/myfolder"]; Then  Mkdir/myfolderfi#shell determine the file, whether the directory exists or has permissions folder= "/var/www/" file= "/var/www/log" #-x parameter to determine $folder Whether it exists and has enforceable permissions if [!-X ' $folder];  Then  mkdir the "$folder" fi#-D parameter to determine if there is an IF [!-D "$folder"]; then  mkdir "$folder" fi#-F parameter to determine if $file exists if [! -F "$file"]; Then  touch "$file" fi#-N to determine if a variable has a value if [!-n "$var"]; then  echo "$var is empty"  exit 0fi# determine if two variables are equal if ["$va R1 "=" $var 2 "]; Then  echo ' $var 1 eq $var 2 ' else  echo ' $var 1 not EQ $var 2 ' fi

Shell determines whether a file or folder exists

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.