See also:
The bash has three default file descriptors for each process:
- 0 ...
stdin
- 1 ...
stdout
- 2 ...
stderr
Assuming the terminal is /dev/tty0
then all three point to it on process launch.
command 1> file # redirect stdout
command 2> file # redirect stderr
command &> file # redirect both stdout and stderr
command >file 2>&1 # same as above, mor idiomatic
command > /dev/null # discard output
command < file # redirect stdin
cmd1 | cmd2 | cmd3 # pipe commands, connect stdout of one with stdin of next
echo ${PIPESTATUS[@]} # show exit codes of each piped command
See also: http://www.catonmat.net/blog/bash-one-liners-explained-part-three/
stat
type
which
cat /etc/*-release
cat /proc/version
cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/diskstats
uname -a
ulimit -n
free -t -m
dmidecode -t
timedatectl status
chkconfig
date +"%Y-%m-%d" # e.g.: 2015-12-31
date +%s # Unix epoch
date -u +"%Y-%m-%dT%H:%M:%SZ" # ISO 8601 timestamp UTC
date +%FT%TZ # ISO 8601 timestamp local time
diff -u warden.conf warden.conf.old
cat /etc/passwd | cut -d ":" -f1
xxd -l $LINES
Reverse search: Ctrl+R
Cancel search: Ctrl+G
Show 10 entries:
history 10
Repeats the previous command (and replace bits):
!!:s/foo/bar
free -th
Render disk usage (in a human readable form) for given dir:
du -h opt/
Render free disk space (in a human readable form):
df -h
Display continuous device report at 2s intervals:
iostat -d 2
Linux:
ldd
macOS:
otool -L
top -U $USER
ps -e | grep python
ps faux
script
lsmod
hostname --fqdn
sudo tcpdump -i any port 53
Modern:
ip a
ip a show dev eth0
Outdated:
ifconfig -a
ifconfig eth0
lsof -i TCP:X
sudo ss -lptn
lsof -n -i4TCP
Linux:
ss -nl
macOS/outdated:
netstat -nl | grep PORT
Linux:
ip route
macOS/outdated:
netstat -nr
tcpdump
tc -d -s -p qdisc show
nfsstat
Lowercases and replaces underscores with dots:
echo 'Com_Acme_Library' | tr '_A-Z' '.a-z'
Replaces foo
with quux
:
cat 'foo bar baz' | sed -e 's/foo/quux/'
for i in $(cat input.txt); do echo $i; done;
cat input.txt | xargs -n1 sha1sum
cat << 'EOF' > $FILENAME
$LINE1
$LINE2
EOF
cat > $FILE
# CTRL+D to save
dd if=/dev/zero of=output.dat bs=1024 count=1000 # creates a 1MB file (1000x1kB blocks)
strings /dev/urandom | tr -c -d '0-9' | dd of=randnum.dat bs=1 count=1M
ls -l opt/ | wc -l
find opt/ -name ".txt"
find . -type f -exec grep -H FINDME {} \;
Setup and config: https://github.com/mhausenblas/mhausenblas-config/blob/master/home/.tmux.conf
: new -s XXX … create a new session XXX
: kill-session -t XXX … kill session XXX
$ … rename session
L … toggle sessions
s … list sessions
" … split pane horizontally
z … full screen toggle pane
x … kill pane
Spacebar … toggle layout
arrows … switch panes
? … shortcuts
d … detach
git rev-parse HEAD
git tag TAG HASH git push origin TAGNAME … sync
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm
curl -L -C - -b "oraclelicense=accept-securebackup-cookie" -O http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm
echo 'Main-Class: Test' > mymanifest
jar -cfvm mytest.jar mymanifest Test.class
java -jar mytest.jar
grep -ri "org.openanzo.client.jena" *
Collection of recipes.
ssh-keygen -y -f /path/to/privatekey > /path/to/publickey
tail -f abc.log
less +F abc.log # hit SHIFT+F for refresh
less +/foo # highlight term as regexp
To convert a collection of PNGs into an animated GIF with an delay of 0.5s go:
convert -delay 50 *.png output.gif
See also http://www.imagemagick.org/Usage/anim_basics/
Monitor Docker state:
watch -n 3 'date >> dump_ps && docker ps | tee -a dump_ps'
See also http://tinystruggles.com/2015/03/22/bash-monitoring-tips.html
defaults write com.apple.finder CreateDesktop -bool false && killall Finder
yes | tr \\n x | head -c 450m | grep n