Test options
-b file
|
True if file is a Block special device
|
-c file
|
True if file is a Character special device
|
-d file
|
True if file is a Directory
|
-e file
|
True if file Exists
|
-g file
|
True if file has its set-group-id bit set
|
-G file
|
True if file is owned by the current effective group id
|
-k file
|
True if file has its "sticky" bit set
|
-L file
|
True if file is a symbolic Link
|
-O file
|
True if file is owned by the current effective user id
|
-p file
|
True if file is a named Pipe
|
-r file
|
True if file is readable
|
-S file
|
True if file is a Socket
|
-s file
|
True if file has a Size greater than zero
|
-t [FD]
|
True if FD is opened on a terminal. If FD is omitted, it defaults to 1 (standard output)
|
-u file
|
True if file has its set-user-id bit set
|
-w file
|
True if file is writable
|
-x file
|
True if file is executable
|
file1 -ef file2
|
True if file1 and file2 have the same device and inode numbers, i.e., if they are hard links to each other
|
File age
file1 -nt file2
|
True if file1 is newer than file2
|
file1 -ot file2
|
True if file1 is older than file2
|
String tests
-z String
|
True if the length of String is zero
|
-n String
|
True if the length of String is nonzero
|
String1 = String2
|
True if the strings are equal
|
String1 != String2
|
True if the strings are not equal
|
Numeric tests
ARG1 -eq ARG2
|
True if ARG1 is equal ARG2
|
ARG1 -ne ARG2
|
True if ARG1 is not-equal ARG2
|
ARG1 -lt ARG2
|
True if ARG1 is less-than ARG2
|
ARG1 -le ARG2
|
True if ARG1 is less-than-or-equal ARG2
|
ARG1 -gt ARG2
|
True if ARG1 is greater-than ARG2
|
ARG1 -ge ARG2
|
True if ARG1 is greater-than-or-equal ARG2
|
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
|
!$
|
Last argument of previous command
|
ALT-.
|
Last argument of previous command
|
!*
|
All arguments of previous command
|
^abc^123
|
Run previous command, replacing abc with 123
|
Bash Parameter Expansions
${parameter}
|
Value of parameter
|
${parameter:-word}
|
Use default
|
${parameter:=word}
|
Assign default
|
${parameter:?word}
|
Display Error
|
${parameter:+word}
|
Use Alternate
|
${parameter:offset}
|
Substring
|
${parameter:offset:length}
|
${!name[@]}
|
List Array Keys
|
${#parameter}
|
Parameter length
|
${parameter#match}
|
Remove prefix
|
${parameter##match}
|
(longest)
|
${parameter%match}
|
Remove suffix
|
${parameter%%match}
|
(longest)
|
${parameter/pattern/string}
|
Substitution
|
${parameter^pattern}
|
Uppercase match
|
${parameter^^pattern}
|
Uppercase all
|
${parameter,pattern}
|
Lowercase match
|
${parameter,,pattern}
|
Lowercase all
|
Sed commands
:[label]
|
Set label
|
Zero/One address commands
|
=
|
Print current line number
|
a \
|
Append text
|
text
|
(embedded newlines)
|
Address range commands
|
b [label]
|
Jump to label
|
t (T) [label]
|
Jump to label on (failed) s///
|
c \
|
Replace match
|
text
|
(Embedded newlines)
|
d (D)
|
Delete (to newline)
|
h H
|
Copy/Append pattern
|
g G
|
Paste/Append hold
|
x
|
Exchange hold/pattern
|
n N
|
Read/Append next line
|
p
|
Print pattern
|
s/regex/replace/
|
Substitution
|
Addresses
|
first~step
|
Starting at first, every stepth
|
/regex/
|
Lines matching regex
|
addr1,+N
|
addr1 and N following lines
|
Various
|
{c1;c2;c3;}
|
List of commands
|
;
|
Separate commands
|
References
ftp.psu.ac.th/pub/bash-howto/reference_bash-cheat.pdf
sed.sourceforge.net/sed1line.txt
devhints.io/bash
|