Useful commands
Numeric permission list of all directories/files
Can be useful to restore in case of a fatal chmod -R 777 /.
find / | xargs stat -c 'chmod %a "'%n'"'
Check if your webserver supports gzip compression with curl
curl -I -H "Accept-Encoding: gzip,deflate" http://example.org
Highlight changing network information (rx,tx etc.)
watch -n 2 -d '/sbin/ifconfig eth0'
Start xen guest and attach to virtual console
To access grub and see bootup messages
xm create -c vmname
Which package holds that file?
# Red Hat
rpm -qf /bin/mount
# Debian
dpkg -S /bin/mount
Which packages were installed lately?
# Red Hat
rpm -qa --last | tac
# Debian
grep -E '(UPGRADE|INSTALL)' /var/log/aptitude
Replace in-file (or in-place edit) with Perl
perl -pi -e 's/oldtext/newtext/' file.txt
ldapsearch with TLS
ldapsearch -x -Z ldapserver
Capturing traffic with tcpdump
tcpdump -i eth3 tcp port 389 -w /root/tcpdump.txt
Open reverse SSH tunnel
ssh -L localport:destination:port user@gateway
MySQL: show extended table info like collation, privileges etc.
SHOW FULL COLUMNS FROM tblname;
Read hardware sensors from Sun server
ipmitool -v -U username -H 192.168.1.1 sdr list all
Solaris: Determine which package a file belongs to
pkgchk -l -p /path/to/file
grep filename /var/sadm/install/contents
Pad single-digit fields in MAC addresses (by Yannick Denzer)
echo "a:0:1:0:a:43" | sed -E 's/[^:]+/0&/g;s/[^:]([^:][^:])/\1/g'
Show compiled and shared modules loaded in Apache
/usr/bin/httpd -t -D DUMP_MODULES
Delete a block of text with sed
sed "/startOfBlock/,/endOfBlock/d" file.txt
MacPorts: upate ports tree and upgrade packages
port selfupdate && port upgrade outdated
Debian: hold a package to prevent updating
echo linux-image-2.6-686-bigmem hold | dpkg --set-selections
Get IP address from ifconfig output
# Linux
ifconfig eth0 | awk -F ' *|:' '/inet addr/{print $4}'
# OS X
ifconfig en1 | awk -F ' *|:' '/inet /{print $2}'
Shell: convert UNIX timestamp to an human-readable format
date -d @1305547782
mpd: play next song matching ‘infernal war’
while true; do mpc next | grep -qi 'infernal war' && break; done
Put init script to standard runlevels
# Debian
update-rc.d nagios defaults
# RHEL
chkconfig on ntpd
Sort output by column (separator = $IFS)
ps aux | sort -nk 6
Convert .ts (MPEG-TS) files
mencoder sourcefile.ts -oac mp3lame -ovc lavc -lavcopts aspect=16/9 -o out.avi
OpenSSL: display fingerprint of a certificate
"type" is md5, sha1, sha256 etc.
openssl x509 -fingerprint -noout -in newcert.pem -<type>
OpenSSL: get remote certificate
openssl s_client -connect foo.example.org:443
OpenSSL: display certificate details
openssl x509 -in /path/to/cert -text
Solaris zone commands
zoneadm list -iv # on global zone, list all zones
256 color terminal stuff
tput colors # get colors
export TERM=xterm-256colors # if installed
xrdb -load $HOME/.Xdefaults # to activate color changes in X terminals
Horde Webmail with IMAP proxy, thread sort error
If you encounter errors when opening folders sorted in a special way (by threads for example), just run (Horde Groupware 4+):
horde-clear-cache
SGD connection fails with "Failed to install SGD Client" on Debian 6 (64bit)
I was missing some 32-bit libraries. Install the ia32-libs package, then the problem should besolved.
user@host:~$ ldd .tarantella/tcc/4.50.937/ttatcc
linux-gate.so.1 => (0xf77d5000)
libX11.so.6 => /usr/lib32/libX11.so.6 (0xf769e000)
libXmu.so.6 => /usr/lib32/libXmu.so.6 (0xf7688000)
libXt.so.6 => /usr/lib32/libXt.so.6 (0xf7635000)
libXext.so.6 => /usr/lib32/libXext.so.6 (0xf7626000)
libSM.so.6 => /usr/lib32/libSM.so.6 (0xf761e000)
libICE.so.6 => /usr/lib32/libICE.so.6 (0xf7607000)
libpthread.so.0 => /lib32/libpthread.so.0 (0xf75ee000)
libdl.so.2 => /lib32/libdl.so.2 (0xf75ea000)
libgcc_s.so.1 => /usr/lib32/libgcc_s.so.1 (0xf75cb000)
libc.so.6 => /lib32/libc.so.6 (0xf7484000)
/lib/ld-linux.so.2 (0xf77d6000)
libxcb.so.1 => /usr/lib32/libxcb.so.1 (0xf746b000)
libuuid.so.1 => /lib32/libuuid.so.1 (0xf7467000)
libXau.so.6 => /usr/lib32/libXau.so.6 (0xf7464000)
libXdmcp.so.6 => /usr/lib32/libXdmcp.so.6 (0xf745e000)