Last active
January 1, 2016 22:19
-
-
Save cowboy-cod3r/8209195 to your computer and use it in GitHub Desktop.
Some handy bash conditional checks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Integer comparison | |
-eq | |
-ne | |
-gt | |
-ge | |
-lt | |
-le | |
Things to check for in conditional | |
-z - checks to see if a string is null (zero length) | |
-n - checks to see if a string is not null | |
-a file - file exists | |
-d file - file is a directory | |
-f file - file is a regular file | |
-r file - You have read permission on file | |
-s file - file exists and is not empty | |
-w file - You have write permission on file | |
-x file - You have execute permission on file | |
-O file - You own file | |
-G file - Your group ID is the same as that of file | |
file1 -nt file2 - file1 is newer than file2 (based on modification date) | |
file1 -ot file2 - file1 is older than file2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment