Skip to content

Instantly share code, notes, and snippets.

@cowboy-cod3r
Last active January 1, 2016 22:19
Show Gist options
  • Save cowboy-cod3r/8209195 to your computer and use it in GitHub Desktop.
Save cowboy-cod3r/8209195 to your computer and use it in GitHub Desktop.
Some handy bash conditional checks
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