1. Cheat Sheet Bash Command
  2. Bash Cheat Sheet Shortcuts
  3. Linux Bash Cheat Sheet

Everything that can be useful in test constructs (if statements) in a bash environment.

This cheat sheet is based on the Advanced Bash-Scripting Guide by Mendel Cooper.

Man command Show manual for command Bash Shortcuts CTRL-c Stop current command CTRL-z Sleep program CTRL-a Go to start of line CTRL-e Go to end of line CTRL-u Cut from start of line CTRL-k Cut to end of line CTRL-r Search history!! Repeat last command!abc Run last command starting with abc!abc:p Print last command starting with abc. Basic Linux commands. Description ls Lists all files and directories in the present working directory. This cheatcheat will help you to improve your skills in bash, There are 2 columns, the left one is the command in parent­hesis ex (C-j) = Ctrl + j and the right one will do a simple descri­ption. The Notes Section could help to resolve some problems or include features into your Terminal. This Bash cheat sheet contains commands to help you with the following types of tasks: History. File and navigation. Keyboard shortcuts. Running commands in sequence. To download this cheat sheet, log in or enter your email address and country below.

Bash cheat sheet pdf

Compound Comparison

-a

Similar to &&

-o

Similar to ||

Git bash cheat sheet

Cheat Sheet Bash Command

Integer Comparison

Bash Cheat Sheet Shortcuts

-eq

if [ '$a' -eq '$b' ]

-ne

if [ '$a' -ne '$b' ]

-gt

if [ '$a' -gt '$b' ]

-ge

if [ '$a' -ge '$b' ]

-lt

if [ '$a' -lt '$b' ]

-le

if [ '$a' -le '$b' ]

<

(within double parentheses)

(('$a' < '$b'))

<=

(within double parentheses)

(('$a' <= '$b'))

>

(within double parentheses)

(('$a' > '$b'))

>=

(within double parentheses)

(('$a' >= '$b'))

String Comparison

=

The comparison operator behaves differently within a double-brackets test than within single brackets.

!=

This operator uses pattern matching within a [[ ... ]] construct.

<

Note that the < needs to be escaped within a [ ] construct.

>

Note that the > needs to be escaped within a [ ] construct.

-z

that is, has zero length

-n

File Test Operators

Cheat

-e

-a

-a is deprecated and its use is discouraged.

-f

file is a regular file (not a directory or device file)

-d

file is a directory

-h

-L

file is a symbolic link

-b

file is a block device

-c

file is a character device

-p

file is a pipe

-S

file is a socket

-s

file is not zero size

-t

file (descriptor) is associated with a terminal device

This test option may be used to check whether the stdin [ -t 0 ] or stdout [ -t 1 ] in a given script is a terminal.

-r

file has read permission (for the user running the test)

-w

file has write permission (for the user running the test)

-x

file has execute permission (for the user running the test)

-g

set-group-id (sgid) flag set on file or directory

-u

set-user-id (suid) flag set on file

-k

sticky bit set

-O

you are owner of file

-G

group-id of file same as yours

-N

file modified since it was last read

-nt

file f1 is newer than f2

-ot

file f1 is older than f2

-ef

files f1 and f2 are hard links to the same file

!

'not' -- reverses the sense of the tests above (returns true if condition absent).

Notes

Linux Bash Cheat Sheet

Based on the Advanced Bash-Scripting Guide by Mendel Cooper.