• Printable version
Personal tools
Wikipedia Affiliate Button

Linux Cheat Sheet

From BrightByte

Jump to: navigation, search

Some things handy to know when dealing with a Linux shell. Unsorted, incomplete, subjective list.



starts a new screen session (vistual console)
ctrl-a d
disconnects from a session
screen -rd
reconnects to a session;
ctrl-a esc
copy mode, for selecting and scrolling. Hit esc again to get out.
ctrl-a 0
selects window 0. (works for all numbers to 9)
ctrl-a "
list windows
ctrl-a Ctrl-c
new window


refresh file database (after manual install) -- this is for tetex (and texlive?); MiKTeX uses initexmf -u
manual install of ctan packages
  • latex *.ins (extracts styles, etc)
  • latex *.dtx (makes documentation)
  • move styles, etc to /usr/share/texmf-*/tex/xxx
  • update file database
renaming auto-generated sections


arp -a
show everything on the local link
arp -na host
show ARP entry
arping host
ARP-ping host
Like ping and tracepath combined
look who's on the network
netcat's big brother
the obvious
ping, tracepath, nmap, netstat, nettop
tcpdump, tcpick, tcpspy, iperf
download mms stream
mplayer mms:// -dumpstream -dumpfile foo.wmv
tcpdump -w test.pcap -s 1550 dst and tcp port 80
capture traffix on port 80 to a given IP
tcpflow -i any -C -e port 12345
capture tcp traffic from/to port 12345
iptables -A OUTPUT -p tcp --dport 12345 -j REJECT --reject-with tcp-reset
kills connections to a specific port


penssl s_client -state -debug -connect host:port
detailed debug trace of SSL handshake. Good way to find out what cypher is used.


echo 105:95:85:75:70 > /proc/acpi/thermal_zone/THRM/trip_points
set thermal trip points
echo 5 > /proc/acpi/thermal_zone/THRM/polling_frequency
set polling frequency

To show thermal status:

cat /proc/acpi/thermal_zone/THRM/temperature
cat /proc/acpi/thermal_zone/THRM/state
cat /proc/acpi/processor/*/limit
cat /proc/acpi/processor/*/throttling

Couldn't figure out where to configure that, so i write myself a small init.d script to set trip points and polling (which was disabled per default, causing overheating & reboots - thanks Feisty...)

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
show available cpu frequencies. Use scaling_cur_freq to get current frequency, cpuinfo_cur_freq appears to get confused about cpu numbers.
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
show available cpu governors (scaling policies). Use scaling_governor to get current frequency.
CPU frequency settings, provided by package gnome-applets (for whatever reason)
-f: set frequency
-g: set governor

Power Management

Per default, GNOME uses the estimated time to discharge to trigger emergency hibernation. This sucks if you have a wonky battery. To force GNOME to use the percentage charged to trigger hibernation, use this:

gconftool-2 --type bool --set /apps/gnome-power-manager/general/use_time_for_policy false

To see all power management settings, use:

gconftool-2 --s /apps/gnome-power-manager/general
gconftool-2 --s /apps/gnome-power-manager/thresholds


initctl (start, stop, status)
control init jobs
control runlevels, inaddition to /etc/rc*.d
init, telinit
switch runlevel (0: halt; 1: single-user; 2-4: multi-user cli; 5: multi-user X; 6: reboot; S,s: swicth to single-user; a-c: on-demand)
configure job start/stop at runlevel (or even remove job from rc*.d)
System administrators are not encouraged to use update-rc.d to manage runlevels. They should edit the links directly or use runlevel editors such as sysv-rc-conf and bum instead.
telinit level
sets the runlevel
  • S: single user, no network, no deamons
  • 0: halt
  • 1: single user, no network, no deamons
  • 2: multi-user, no network, no deamons
  • 3: multi-user, text
  • 4: unused
  • 5: multi-user, with X
  • 6: reboot


  • To temporarily disable some page: Redirect 503 /path/to/page.html


Update alsa from source

sudo apt-get install module-assistant
sudo m-a update
sudo m-a prepare
sudo m-a a-i alsa
sudo alsa force-unload
sudo depmod -ae
sudo modprobe snd-hda-intel

I needed to do this on Hardy Heron to get alsa to work properly


console mouse service (because i always forget what it's called)

kernel params

80x50 characters vga text mode for virtual console (for some reason, this screws with the boot splash though)

console tricks

(some from [1])

fuser -k /media/cdrom
kill processes using /media/cdrom
restore a hosed terminal to normal
wake up terminal after suspend with ctrl-s
screen -S foo
start a screen session named "foo"
screen -x foo
join screen session named foo without disconnecting the other terminal. Input and putput works for both!.
tail -n +2
passes all but the first line of output. Useful for stripping headers
start-stop-daemon --start
starts a given program only if its not already running. Supports various options, see man page.
starts a program and restarts it when it dies. Supplied by daemontools/svtools.
sed -n '3~3p'
print every 3rd line
awk '{if (++count%3==0) print $0;}
print every 3rd line
perl -ne 'print if($.%3==0)'
print every 3rd line
readlink -f
resolve to absolute, real path. Poor man's realpath.
ls -1 | tr '\n' ':'
list of files names separated by ":" (nice for building a path)
read x y z <<< "$foo"
break a variable into words [2]
read x y z < <(echo a b c)
piping something into read [3]
cat /proc/loadavg
system load, without calling uptime
cut -c1-80
truncate lines at 80 chars
wrap lines
set -o ignoreeof
do not terminate shell on EOF
shell function for pasting to a bin
pastebin() { curl -F 'sprunge=<-'; }
[[ $0 = /* ]] && echo "$0" || echo "$PWD/${0#./}"
determin a script's own location (hopefully). see for a full discussion.
measure throughput through a pipe. handy to show progress on long running pipe jobs.
rsync -r A/ B/
copy the content of directory A into directory B (including all dot files, etc). Note that A/ will copy the contents of A, while just A will copy the directory (with its contents).
(thanks to hyphenated of #bash for this one)
post to pastebin

SSH / Login

passwd -d <user>
disables password-based login for that user, both via ssh and locally. Unlike passwd -l, the acccount is not expired, and can be accessed via public key authentication, etc.
getent passwd <user>
look up the user not only in /etc/passwd but also NIS, LDAP, Samba, etc.
shopt | grep login_shell
is this a login shell?
echo $TERM | grep linux
is this a (linux) text terminal (vterm)?
export TMOUT=300
cause shell to automatically close after 5 minutes of inactivity.

shell scripts

set -e
script exists on any error.
set -u
treat unset variables as errors


mutt -x -a somefile -s "some message" your@address < /dev/null
send mail with file attachment from the command line (no body)

system info

from [5]

cat /proc/cpuinfo
cpu make, speed, etc
BIOS info
ethtool -i eth0
network card info


loadkeys keymaps-file


keycode 66 = ISO_Level3_Shift
Makes CapsLock behave like AltGr - nice for programmign on a german keyboard

Configuration can be done in ~/.Xmodmap.

To execute automatically, put this into your ~/.xsessionrc:

 if [ -f ~/.Xmodmap ]; then
       xmodmap ~/.Xmodmap

NOTE: apparently, KDE overrides these settings, unless you use setxkbmap [6]. Investigating...

To find out key codes, use xev

My .Xmodmap file:

keycode  66 = ISO_Level3_Shift
keycode  49 = asciicircum degree notsign notsign dead_circumflex dead_abovering
keycode  21 = apostrophe grave cedilla cedilla dead_acute dead_grave
keycode  34 = udiaeresis Udiaeresis diaeresis diaeresis dead_diaeresis dead_diaeresis
keycode  35 = plus asterisk asciitilde macron asciitilde dead_tilde


 sudo dpkg-reconfigure keyboard-configuration

To not change anything, just hit enter. The last screen allows you to enable ctrl+alt+backspace for killing the x-server.

File System

lsof name
shows processes using a file or device

i18n files

  • Merge Multiple .po files into one: msgcat /tmp/*.po | msgfmt -o l10n/fr_CA/LC_MESSAGES/ -
  • Compile: msgcat *.po | msgfmt -o -


Alt-SysRq-something lets you talk directly to your system. See [7] for a list of commands. Here are the meanings of a few Alt-SysRq keys:

kill all processes, except ini
dump current tasks
dirty reboot (no disk sync!)
dirty shutdown

See /proc/sys/kernel/sysrq to find out if Alt-SysRq is enabled.

To trigger a SysRq programatically, use echo x > /proc/sysrq-trigger

Baby Mode

lock input but not the screen until pw is entered


  • save current session:
    dbus-send --dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.saveCurrentSession


manipulate video mode & resolution at runtime
bind hotkeys


:set paste
enable past mode, disable auto-indent
:syntax on
enable syntax highlighting
:w !sudo tee %
save file with root permissions


host foo
lookup at a specific host
host -t srv foo
lookup of a specific record type
dig foo @
detailed lookup with dig, at a specific host
  • When changes to DNS fail to take effect:
    • check /etc/hosts for hard coded entries
    • check /etc/resolv.conf for which DNS server will be used
    • restart dnsmasq if running
    • restart nscd if running
getent hosts <hostname>
resolves the host name, but also considers /etc/hosts (which host and dig don't do)


  • in /etc/default/rcS set UTC=yes
  • use hwclock --set --utc --date="...."


log outgoing tcp connections to port $foo
iptables -A OUTPUT -p tcp -m state --state NEW --dport $foo -j LOG --log-ip-options --log-tcp-options --log-prefix "DIRTY FOO: " --log-uid --log-level warn
see output with dmsg or via syslogd.


tweak disk parameters
hdparm -t <device>
raw read benchmark
advanced i/o benchmarks
show labels and uuids for block devices


pulseaudio -k 
gnome-session-save --kill
terminate session (with gui prompt)
/etc/init.d/gdm restart
kill all sessions (no prompt)
unity --replace --display :0 & disown
(re)start unity without losing the current session. also works from a ctrl-alt-f4 virtual console.
compiz --replace --display :0 & disown
(re)start compiz (and unity) without losing the current session. also works from a ctrl-alt-f4 virtual console.
gsettings set org.gnome.desktop.interface text-scaling-factor 0.9
set font scaling catory to 0.9

See Also