Shellmagic PDF
Shellmagic PDF
xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Flag Description
File exists
file is a directory
file is a pipe
file is a socket
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
file has read permission (for the user running the test)
file has write permission (for the user running the test)
file has execute permission (for the user running the test)
1 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Flag Description
Not -- reverses the sense of the tests above (returns true if condition
absent).
Job Identifiers
Job control allows you to selectively stop (suspend) the execution
of processes and continue their execution at a later point in time.
Notation Description
Last job
Signals
UNIX System V Signals.
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Name Number Action Description
1 exit Hangs up
2 exit Interrupts.
Software termination
15 exit
signal.
Flag Description
is equal to
is not equal to
is greater than
3 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Flag Description
is less than
Flag Description
is equal to
is not equal to
Compound Operators
Useful for boolean expressions and is similar to and . The
compound operators work with the command or may occur within
single brackets
Flag Description
logical and
logical or
4 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
List Constructs
Provides a means of processing commands consecutively, alas
effectively being able to replace complex if/then/case structures.
Construct Description
and construct
or construct
Exit Code
Description
No.
The interrupt signal, sends SIGINT to the job running in the foreground.
5 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Key Combo Description
user can foreground, background or kill the process. Delayed suspend is only
available on operating systems supporting this feature.
String Manipulation
Bash supports a suprisingly big number of string operations!
Pattern Description
Substring
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
GlobbingExpressions
BuiltinsOverview
Pattern Description
7 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
GlobbingExpressions
BuiltinsOverview
Pattern Description
Variable Operations
Perform operations on variables.
Expression
File Types
This is very different from Windows but straightforward once you get
it. You may also have heard the expression "everything is a file in
Linux".
Symbol Meaning
Regular file
Directory
Link
Special file
8 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Symbol Meaning
Named pipe
Block device
Code Description
user permissions
group permissions
owner permissions
Command Parameters
Command parameters, also known as arguments, are used when invoking
a Bash script.
Command Description
Parameter 1 ... 9
9 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Command Description
Current options
The underscore variable is set at shell startup and contains the absolute
file name of the shell or script being executed as passed in the argument
list. Subsequently, it expands to the last argument to the previous
command, after expansion. It is also set to the full pathname of each
command executed and placed in the environment exported to that
command. When checking mail, this parameter holds the name of the mail
file.
Number of arguments
History Expansion
Enables use and manipulation of previous commands.
Command Description
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Command Description
Bash Globbing
Bash cannot recognize RegEx but understand globbing. Globbing is
done to filenames by the shell while RegEx is used for searching
text.
Glob Description
Regular Expressions
Always use quotes in your RegEx to avoid globbing
11 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Operator Effect
The preceding item is matched at least N times, but not more than M
times.
Represents the range if it's not first or last in a list or the ending point of
a range in a list.
Matches the empty string at the beginning of a line; also represents the
characters not in the range of a list.
Shell Builtins
Shell builins are built into Bash are often very (if not extremely)
fast compared to external programs. Some of the builtins are
inherited from the Bourne Shell ( ) — these inherited commands
will also work in the original Bourne Shell.
12 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Builtin Description
Reads and executes commands from a designated file in the current shell.
Removes the specified jobs from the jobs table for the process.
13 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Builtin Description
Builtin Description
Reads one line of data from STDIN, and assigns it to a variable that can’t be
changed.
Forces a function to exit with a value that can be retrieved by the calling
script.
Reads and executes commands from a designated file in the current shell.
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Builtin Description
Waits for the specified process to complete, and returns the exit status.
is used for saving output of commands that are send to run in a subshell.
is used for testing and is a built-in. Is useful in some cases for filename
expansion and string manipulation.
is used for testing. This is the one you should use unless you can think of a
reason not to.
15 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Symbol Quick Reference
Used for process substitution and is similar to a pipe. Can be used whenever a
command expects a file and you can use multiple at once.
used for sending output to a file and erasing any previous content in that file.
logical or
logical and
double quotes are used to preserve the literal value of all characters
except , and
16 of 17 2/14/20, 9:06 AM
Shell Magic - The Ultimate Bash Cheatsheet! https://shellmagic.xyz/
File Integer String CompoundString Command History Bash Regular Shell Symbol
Testing
Comparison
Comparison
Operators Manipulation
ParametersExpansion
Globbing
Expressions
BuiltinsOverview
Symbol Quick Reference
used for linking together arithmetic operations. All are evalutated but only
the last is returned
[email protected] SEND
©2020 | Suggest an Enhancement or Contribute to The Site | View our Privacy Policy
17 of 17 2/14/20, 9:06 AM