Skip to content

Instantly share code, notes, and snippets.

@jhnlsn
Last active August 29, 2015 13:56
Show Gist options
  • Save jhnlsn/9336561 to your computer and use it in GitHub Desktop.
Save jhnlsn/9336561 to your computer and use it in GitHub Desktop.
Bash Cheat Sheet
-r file #Check if file is readable.
-w file #Check if file is writable.
-x file #Check if we have execute access to file.
-f file #Check if file is an ordinary file (not a directory, a device file, etc.)
-s file #Check if file has size greater than 0.
-d file #Check if file is a directory.
-e file #Check if file exists. Is true even if file is a directory.
if [ -f file ] ; then
# File exists
fi
n1 -eq n2 #Check to see if n1 equals n2.
n1 -ne n2 #Check to see if n1 is not equal to n2.
n1 -lt n2 #Check to see if n1 < n2.
n1 -le n2 #Check to see if n1 <= n2.
n1 -gt n2 #Check to see if n1 > n2.
n1 -ge n2 #Check to see if n1 >= n2.
if [ $NUM -gt 2 ];
then
#do something
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment