Linux Shell Test keyword

Source: Internet
Author: User

1) Judgment expression

IfTest (expression is true)

IfTest! expression is False

Test expression 1–a expression 22 expressions are true

Test expression 1–o Expression 22 expressions have a true


2) Judging the string

Test–n string string is not zero in length

Test–z string string has a length of zero

Test string 1 = string 2 string equal

Test string 1! = String 2 String unequal


3) Judging integers

Test integer 1–eq integer 2 integer equal

Test integer 1–ge integer 2 integer 1 greater than or equal to integer 2

Test integer 1–gt integer 2 integer 1 greater than integer 2

Test integer 1–le integer 2 integer 1 less than or equal to integer 2

Test integer 1–lt integer 2 integer 1 less than integer 2

Test integer 1–ne integer 2 integer 1 not equal to Integer 2



4) Judgment document

Test File1–ef File2 Two files with the same device number and I node number

Test file1–nt File2 file 1 newer than file 2

Test File1–ot File2 file 1 older than file 2

Test–b file files exist and are block device files

Test–c file files exist and are character device files

Test–d file files exist and are directories

Test–e file files exist

test–f file files exist and are regular files

Test–g file exists and the group ID is set

Test–g file files exist and belong to valid group ID

Test–h file exists and is a symbolic link (same-l)

Test–k file files exist and sticky bits are set

Test–b file files exist and are block device files

Test–l file exists and is a symbolic link (same-h)

Test–o file files exist and belong to valid user ID

Test–p file exists and is a named pipe

Test–r file files exist and are readable

Test–s file exists and is a socket

test –t fd                                The                file descriptor is a   that is opened at a terminal;

test –u file                               The               file exists and sets its Set-user-id bit  

test –w file                              The               file exists and is writable  

< Span class= "Hilite2" >< Span class= "Hilite2" >< Span class= "Hilite2" >< Span class= "Hilite2" >
test –x File                                              file exists and executable

Linux Shell Test keyword

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.