Toolbox
  • Printable version
 
TOOLBOX
LANGUAGES
Language
Categories
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.

Contents

Screen

screen
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

TeX

texhash
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
\listofalgorithms
\renewcommand{\listalgorithmname}{Algorithmenverzeichnis}
\printglossary
\renewcommand{\nomname}{Glossar}

Network

arp -na host
show ARP entry
arping host
ARP-ping host
mtr
Like ping and tracepath combined
netdiscover
look who's on the network
socat
netcat's big brother
the obvious
ping, tracepath, nmap, netstat, nettop
monitoring
tcpdump, tcpick, tcpspy, iperf
download mms stream
mplayer mms://.....foo.wmv -dumpstream -dumpfile foo.wmv

ACPI

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.
/usr/bin/cpufreq-selector
CPU frequency settings, provided by package gnome-applets (for whatever reason)
-f: set frequency
-g: set governor

Suspend

Suspending to disk/ram is kind of black magic. It depends a lot on the hardware and OS. Here is what worked for me on Ubuntu Feisty on an ASUS F3JC (this got me on the right track):

  • install µswsusp (use apt, the link is just for info)
  • s2disk just works (as root, of course)
  • s2ram sais "unknown machine", but s2ram -f works fine. more info here.
  • So, edit /usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux resp. hal-system-power-suspend-linux to use that instead of pmi (which is otherwise the first thing it finds and tries).

The only thing that does not quite work is the sound driver: i need to reload the snd_hda_intel module after waking the max up. Annoying, but I can live with it. I could hack it into s2ram, but the problem is that you have to kill all programs using sound in order to reload the module. I for one don't want that to happen automatically.

init.d

initctl (start, stop, status)
control init jobs
/etc/inittab
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)
update-rc.d
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

Apache

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

Modules

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

services

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

kernel params

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

console tricks

from [1]

fuser -k /media/cdrom
kill processes using /media/cdrom
reset
restore a hosed terminal to normal
ctrl-q
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.
supervise
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
fold
wrap lines
set -o ignoreeof
do not terminate shell on EOF

shell scripts

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

mail

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 [4]

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

Keyboard

loadkeys keymaps-file

xmodmap

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
 fi

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

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/civicrm.mo -
  • Compile: msgcat *.po | msgfmt -o civicrm.mo -

Alt-SysRq

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

h
help
i
kill all processes, except ini
t
dump current tasks
b
dirty reboot (no disk sync!)
o
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

xtrlock
lock input but not the screen until pw is entered

KDE

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

xorg

xrandr
manipulate video mode & resolution at runtime
xbindkeys
bind hotkeys

vim

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

DNS

host foo 192.168.0.1
lookup at a specific host
host -t srv foo
lookup of a specific record type
dig foo @192.168.0.1
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

clock

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

iptables

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.

See Also

Links

[talk page]Talk:Linux Cheat Sheet

[edit] Thank You

Very useful ext links! Thank you! Gbaor (Wikiversity) --194.160.89.107 13:13, 13 February 2008 (CET)

[edit] KDE: lock kbd/mouse

to lock input but not the screen ("baby mode"), use xtrlock



The above comments may have been left by visitors.

This site's operators can not take responsibility for the content of such comments.