Index

bash command line

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
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
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

create la alias to do ls -la
alias la="ls -la"