Linux Commands: Shell and Text Processing¶
Shell built-ins and scripting, keyboard shortcuts, redirection, environment variables and text tools.
Part of the Linux commands cheat sheet.
Shell Built-in and Scripting Commands¶
alias — Define or display aliases:
bind — Set Readline key bindings and variables:
break — Exit from a for, while, or until loop:
builtin — Run a shell builtin, passing it args:
case — Conditional construct in shell scripts:
continue — Resume the next iteration of a loop:
declare — Set variables and attributes:
enable — Enable and disable shell builtins:
env — Set environment and execute command, or print environment:
eval — Construct command by concatenating arguments:
exec — Replace the shell with the given command:
exit — Exit the shell:
expect — Programmed dialogue with interactive programs:
export — Set export attribute for shell variables:
expr — Evaluate expressions:
factor — Print the prime factors:
fc — Process command history list:
function — Define shell functions:
for — Loop construct:
if — Conditional construct:
let — Evaluate arithmetic expressions:
printf — Format and print data:
read — Read a line from standard input:
return — Return from a shell function:
select — Generate menus from list of words:
seq — Print a sequence of numbers:
setsid — Run a program in a new session:
shift — Shift positional parameters:
source — Execute commands from a file in the current shell:
type — Display information about command type:
until — Loop construct:
while — Loop construct:
yes — Output a string repeatedly until killed:
sudo — Execute a command as another user:
sleep — Delay for a specified amount of time:
Bash Shortcuts Commands¶
Navigation Shortcuts¶
| Shortcut | Description |
|---|---|
Ctrl + A |
Move to the beginning of the line |
Ctrl + E |
Move to the end of the line |
Ctrl + B |
Move back one character |
Ctrl + F |
Move forward one character |
Alt + B |
Move back one word |
Alt + F |
Move forward one word |
Editing Shortcuts¶
| Shortcut | Description |
|---|---|
Ctrl + U |
Cut/delete text from the cursor to the beginning of the line |
Ctrl + K |
Cut/delete text from the cursor to the end of the line |
Ctrl + W |
Cut/delete the word before the cursor |
Ctrl + Y |
Paste the last cut text |
Ctrl + L |
Clear the terminal screen |
Ctrl + C |
Terminate the currently running command |
History Shortcuts¶
| Shortcut | Description |
|---|---|
Ctrl + R |
Search command history (reverse search) |
Ctrl + G |
Exit history search mode |
Ctrl + P |
Go to the previous command in history |
Ctrl + N |
Go to the next command in history |
IO Redirection Commands¶
cmd < file — Redirect input:
cmd > file — Redirect output (overwrite):
cmd >> file — Redirect output (append):
cmd 2> file — Redirect error output:
cmd 2>&1 — Redirect stderr to stdout:
cmd &> file — Redirect stdout and stderr:
cmd 1>&2 — Redirect stdout to stderr:
cmd > /dev/null — Discard standard output:
cmd1 <(cmd2) — Process substitution:
Environment Variable Commands¶
export VARIABLE_NAME=value — Set and export an environment variable:
echo $VARIABLE_NAME — Display value of a variable:
env — List all environment variables:
unset VARIABLE_NAME — Remove an environment variable:
export -p — List all exported variables:
env VAR1=value COMMAND — Set variable temporarily for a command:
printenv — Display environment variables:
Text Processing and Formatting Commands¶
awk — Pattern scanning and processing language:
aspell — Interactive spell checker:
banner — Print large banner on printer/stdout:
bc — An arbitrary precision calculator language:
col — Filter reverse line feeds from input:
colcrt — Filter nroff output for CRT previewing:
colrm — Remove columns from a file:
column — Columnate lists:
dc — An arbitrary precision calculator:
egrep — Print lines matching a pattern (grep -E):
fgrep — Print lines matching a pattern (grep -F):
fmt — Simple optimal text formatter:
grep — Print lines matching a pattern:
sdiff — Side-by-side merge of file differences:
sed — Stream editor for filtering and transforming text:
tr — Translate or delete characters:
unix2dos — UNIX to DOS text file format converter: