The Joy of Linux commands--test

Source: Internet
Author: User
Tags arithmetic bit set sorts

Official document: Help test

File operators:-A FILE Trueif fileexists. -B FILE Trueif fileis block special. -C FILE Trueif fileis character Special. -D FILE Trueif fileis a directory. -E FILE Trueif fileexists. -F FILE Trueif fileexists and is a regularfile. -G FILE Trueif fileIs set-group-ID. -H FILE Trueif fileis a symbolic link. -L FILE Trueif fileis a symbolic link. -K FILE Trueif filehave its ' sticky'bit set.-P FILE Trueif fileis a named pipe. -R FILE Trueif fileis readable by you . -S FILE Trueif fileexists and is not empty. -S FILE Trueif fileis a socket. -T FD TrueifFD is opened on a terminal. -U FILE TrueifThefileIs set-user-ID. -WFILE TrueifThefileis writable by you . -X FILE TrueifThefileis executable by you . -O FILE TrueifThefileis effectively owned. -G FILE TrueifThefileis effectively owned by your group. -N FILE TrueifThefilehad been modified since it was Lastread. FILE1-nt FILE2 TrueifFile1 is newer than file2 (according to modificationDate). FILE1-ot FILE2 TrueifFile1 is older than file2. FILE1-ef FILE2 Trueiffile1 is a hard link to file2. String operators:-Z STRING Trueif stringIs empty. -n String String Trueif stringis not empty. STRING1=STRING2 TrueifThe strings is equal. STRING1!=STRING2 TrueifThe strings is not equal. STRING1<STRING2 TrueifSTRING1 sorts before STRING2 lexicographically. STRING1>STRING2 TrueifSTRING1 sorts after STRING2 lexicographically. Other operators:-O OPTION TrueifThe Shell option option is enabled. ! EXPR Trueif ExprIsfalse. EXPR1-A EXPR2 TrueifBoth Expr1 and EXPR2 aretrue. EXPR1-O EXPR2 TrueifEither Expr1 OR EXPR2 istrue.  Arg1 OP arg2 arithmetic tests. OP is one of-eq,-NE,-lt,-le,-GT, or-GE. Arithmetic binary operators returntrue ifARG1 is equal, not-Equal, Less-than, Less-than-or-equal, Greater-than, or greater-than-or-equal than ARG2.

Example:

1. Determine if the file exists

[Email protected] test]# test-f demo. SH  -F Demo. SH  Echo truetrue! -F Demo. SH Echo true

2. Determine if the string is empty

[[email protected] test]# var=echotruetrueecho True

3. Compare

[[email protected] test]# var=echotruetrue

The Joy of Linux commands--test

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.