bash
Redirection
stderr
and stdout
to a file
$ command > file 2>&1
Test operators
String
op | desc | example |
---|---|---|
= | is equal to | if [ "$a" = "$b" ] |
== | is equal to | if [ "$a" == "$b" ] |
!= | is not equal to | if [ "$a" != "$b" ] |
< | is less than, in ASCII alphabetical order | if [[ "$a" < "$b" ]]; if [ "$a" \< "$b" ] |
> | is greater than, in ASCII alphabetical order | if [[ "$a" > "$b" ]]; if [ "$a" \> "$b" ] |
-z | string is null, that is, has zero length | if [ -z "$a" ] |
Integer
op | desc | example |
---|---|---|
-eq | is equal to | if [ "$a" -eq "$b" ] |
-ne | is not equal to | if [ "$a" -ne "$b" ] |
-gt | is greater than | if [ "$a" -gt "$b" ] |
-ge | is greater than or equal to | if [ "$a" -ge "$b" ] |
-lt | is less than | if [ "$a" -lt "$b" ] |
-le | is less than or equal to | if [ "$a" -le "$b" ] |
< | is less than | (("$a" < "$b")) |
<= | is less than or equal to | (("$a" <= "$b")) |
> | is greater than | (("$a" > "$b")) |
>= | is greater than or equal to | (("$a" >= "$b")) |
File
op | desc | example |
---|---|---|
-h | file is a symbolic link | if [ -h "$f" ] |
-L | file is a symbolic link | if [ -L "$f" ] |
-S | file is a socket | if [ -S "$f" ] |
-t | file (descriptor) is associated with a terminal device | if [ -t "$f" ] |
-r | file has read permission (for the user running the test) | if [ -r "$f" ] |
-w | file has write permission (for the user running the test) | if [ -w "$f" ] |
-x | file has execute permission (for the user running the test) | if [ -x "$f" ] |
-g | set-group-id (sgid) flag set on file or directory | if [ -g "$f" ] |
-u | set-user-id (suid) flag set on file | if [ -u "$f" ] |
-k | sticky bit set | if [ -k "$f" ] |
-O | you are owner of file | if [ -O "$f" ] |
-G | group-id of file same as yours | if [ -G "$f" ] |
-N | file modified since it was last read | if [ -N "$f" ] |
f1 -nt f2 | file f1 is newer than f2 | if [ f1 -nt f2 "$f" ] |
f1 -ot f2 | file f1 is older than f2 | if [ f1 -ot f2 "$f" ] |
f1 -ef f2 | files f1 and f2 are hard links to the same file | if [ f1 -ef f2 "$f" ] |
! | “not” – reverses the sense of the tests above (returns true if condition absent). | if [ ! "$f" ] |