Shell Script Learning (3) file judgment

Source: Internet
Author: User

The shell commonly used file judgment operators are as follows:

-e file is present

-F file is a normal file (not a directory, device file, linked file)

-S means that the file size is not 0

-D Indicates whether the file is a directory

-B indicates a block device (optical drive, floppy disk, etc.)

-C means a character device (keyboard, sound card, etc.)

-P indicates a pipeline

-H indicates a symbolic link

-S indicates whether the socket

-R,-W,-X Indicates whether the file has readable, writable, executable permissions (refers to the user running the test command)

F1-NT F2 F1 is newer than F2 (new than)

F1-ot F2 F1 is older than F2 (old than)

F1-EF F2 F1 and F2 are hard links to the same file

Use! When the above results are reversed, because the content is more, not listed here. The following example can be used as a programming reference

myfile="Aa.txt"if[!-f $myfile]; Then    Echo$myfile"is not exist"    Touch$myfileElse    Echo$myfile"is exist"fiif[!-s $myfile]; Then    Echo "Hello, my master">$myfileElse    Echo$myfile"is not null"fi

Shell Script Learning (3) file judgment

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.