In Linux shell script, about the commonly used flag [- EQ, GT..] in test and if judgment

1. Determine the “document type” of a document, such as test-e filename whether it exists or not

-e Whether the “Document” exists (commonly used)

-f whether the “Document” exists and is a file (commonly used)

-d whether this “document” exists and is a directory (commonly used)

-b Whether the Document exists and is a Block Device

-c Whether this Document exists and is a Character Device

-s whether this “document” exists and is a Socket file

-p Whether the “Document” exists and is a FIFO (PIPE) file

-l Whether the Document exists and is a link file


-r checks if the document exists and has “readable” permissions

-w checks if the document exists and has the permission to be writable

-x checks if the document exists and has “executable” permissions

-u checks if the document name exists and has the property “SUID”

-g checks if the document name exists and has the attribute “SGID”

-k checks if the document name exists and has a “Sticky bit” property

-s checks if the document exists and is a “non-blank file”

>
>
>
>
>
>
>
>

-nt (newer than) determines whether file1 is newer than file2

-ot (older than) determines whether file1 is older than file2

-ef determines whether file1 and file2 are the same file, which can be used to determine the hard link. The key is to determine if both files point to the same inode

4. About the comparison between two integers, for example test n1 -eq n2

-Eq equals two values.

-Ne is not equal.

-gt n1 is greater than n2 (greater than)

-lt n1 is less than n2 (less than)

-e e n1 is greater than or equal to n2 (greater than or equal)

-le n1 is less than or equal to n2.

5

The test-z string determines if the string is empty and returns true for empty

Test-n string determines that the string is not null and returns false for null

= test -r filename -a-x filename
= test -r filename -a-x filename

– A (and) is both true! Test-r file-a-x file = test-r file-a-x file = test-r file-a-x file = test-r file-a-x file = test-r file-a-x file = test-r file-a-x file = test-r file-a-x file

-O (OR) Either is true! Test-r file-o-x file = test-r file-o-x file = test-r file-o-x file = test-r file-o-x file = test-r file-o-x file = test-r file-o-x file = test-r file-o-x file

! Inverse state, such as test! -x file. Returns true if file does not have x

Read More: