Sie sind auf Seite 1von 1

bash cheat sheet redirecting I/O processes & signals variables

command > file in-background & foo="some value"


Copyright (C) 2014
Felix C. Stegerman <x@obfusk.net>
command >> append bg fg jobs ^Z foo=bar some_command
https://github.com/obfusk/bash-cheatsheet command 2> errors sleep wait kill ps
command < input-file nohup trap pgrep pkill echo $foo
command >&2 # to stderr echo "$foo" # quotes!
getting help history command <<<"this is input" echo "${#foo}" # length
help <builtin> history ^R command >/dev/null # bye exit codes ($?) echo "${foo:0:4}" # "some"
man <command> !! !foo 0 success >0 failure echo "${foo:+alternative}"
echo "${foo:-default}"
les and directories : ${foo:=set_default}
special characters options ls -hl --color=auto globbing system echo "${foo#prefix}" # rm prefix
~`#$&*()\|[]{};'"/?! set shopt ls ?[^a-z]* free top echo "${foo%.ext}" # rm suffix
cd pwd pushd popd mv foo-{bar,baz} su sudo echo "${foo/some/replaced}"
cp ln mv rm
quoting cmd "one argument" mkdir rmdir rename declare env export local unset
echo 'single-quoted: "hi!" ...' chown chmod touch umask arrays
echo "double-quoted: '\$foo=$foo'" du file stat test
readlink which my_ary=( foo bar "a b c" ) special variables # quote "$@" !
basename dirname echo "${my_ary[2]}" $? $! $# $@ $* $1 $2 ...
command "${my_ary[@]}" $PATH $HOME $LINES $COLUMNS
streams
$PS1 shift
cat head tail command substitution shell scripts
awk grep sed tr nd & xargs
cmd1 "$(cmd2 ...)" #!/bin/bash
rev shuf sort uniq diff <( cmd1 ) <( cmd2 ) set -e find /foo /bar -type d \ cmd1 | cmd2 | cmd3 pipes
seq wc # ... -print0 | sort -z | \ echo "${PIPESTATUS[@]}"
column cut paste tee xargs -0 rmdir mkfifo a b; cmd1 <a >b; cmd2 <b >a

arithmetic
miscellaneous bc scripting
(( i = 99, j = i * i )) locales
mktemp renice echo $(( i == 99 ? 42 : 37 )) if test -e file; then echo EXISTS; else echo NOPE; fi
printf iconv strings locale if [ -e x ]; then A; elif [ -e y ]; then B; else C; fi
id groups who $LC_* while read -r; do echo "[$REPLY]"; done
crontab time watch printing for x in "$@"; do echo "[$x]"; done
tar zip for (( i=0; i<10; ++i )); do echo "$i"; done
whiptail zenity lpr lpq lprm lpstat lesystems case "$x" in foo*) echo Y;; *) echo N;; esac
perl python ruby mount fsck select x in A B C; do echo $x; [ -z "$x" ] || break; done
less nano vim networking df dd
ack git tree [[ "$x" =~ ^foo ]]
diff patch hostname cmd1 && cmd2 cmd || true !false test [
cal date ifconfig key bindings ( echo "subshell" ) { cmd1; cmd2; cmd3; } getopts
ping eval "$hopefully_not_evil_code" source
curl wget ^C SIGTERM ^D EOF exit
mutt rsync screen ^A home ^E end ^L clear # function
xdg-open nc say_hi () { local you="$1"; echo "Hi $you"; } return
TAB complete UP/DOWN history

Das könnte Ihnen auch gefallen