Table of contents
bash command line
getting help
getting information on a command
help [bash built-in cmd]
man [cmd]
info [cmd]
tldr [cmd]
curl cheat.sh/[cmd]
figure out of a command is part of the shell or a binary
type [cmd]
find path location of a command
which [cmd]
find binary, man page and source files of command
whereis [cmd]
finding a command related to a term
man -k [term]
apropos [term]
looking a word up in the dictionary
dict [term]
keyboard shortcuts
delete backwards until space
ctrl-w
delete path segment
alt-backspace
edit command line
ctrl-x ctrl-e
basic usage
redirect standard out to file
ls > /tmp/redirect.log
redirect standard error to file
ls 2> /tmp/redirect.log
redirect both to file
ls &> /tmp/redirect.log
redirect sterr to stout
2>&1
print something to the syserr
>&2 echo "error"
echo foo 1>&2
combine output of multiple commands: (prints "A B")
(echo "A" ; echo "B") | xargs echo
{ echo "A" ; echo 'B'; } | xargs echo
the first command can read from stdin: (prints "A B")
echo "A" | (cat - ; echo "B") | xargs echo
echo "A" | { cat - ; echo 'B'; } | xargs echo
write the system output to the console & to a file
echo "show in console and write to file" | tee example.txt
write the system output to the console & append to file
echo "show in console and append to file" | tee -a example.txt
create a fifo queue to pipe contents to another program through a (virtual) file
mkfifo /tmp/fifo
while true; do read line < /tmp/fifo; echo "$line"; done
echo "FOO" >/tmp/fifo # from another terminal
save input & output to file until exit or ctrl + d
script [file]?
wildcards
match all public files
*
match all hidden files
.*
files that end in a number
*[0-9]
files that start with a letter
[a-zA-Z]*
files that don't start with a number
[!0-9]*
Jobs
list jobs (background, foreground and suspended)
jobs
terminate foreground job
CTRL + C
pause foreground job
CTRL + Z
paused job to background
bg [job id]
paused job to foreground
fg [job id]
shorthands
foreground current job (marked with + in jobs output)
%%
%+
foreground previous job (marked with -)
%-
background current job
bg %%
bg %+
background previous job
bg %-
History
show command line history
history
search history dynamically
<CTRL> + R
ssh
<CTRL> + R (repeat)
current command
!#
previous command (executes the command)
!!
execute previous command with root priviliges
sudo !!
string replace in previous command & execute
^find^replace^
replace all occurrences
^find^replace^:&
remove only
^find
excute [n] commands ago
!-[n]
run last command starting with ssh
!ssh
run echo with all arguments to previous command
echo !*
run echo with first argument to previous command
echo !^
echo !:1
run echo with [n]th argument to previous command
echo !:[n]
run echo with argument #2 to my last ln command
echo !ln:2
aliases
list all active aliases
alias
alias -p
create la alias to do ls -la
alias la="ls -la"
bypass aliases when executing command
\[cmd]
terminal mode
set -o vi
set -o emacs