Justin R. Buchanan

on Software Development, Systems Administration, Networking, and Random other Stuff

Linux Cheat Sheet

No blog would be complete without a Linux cheat sheet. I compiled this list when I first started learning Linux, and I’ve had it in my private wiki for a while. This list is mainly just a brain-dump, is not comprehensive, and is mostly targeted at Debian or derivatives.

If you want a good list of quick diagnostic commands, check out First 5 Minutes Troubleshooting A Server.

Get Help for Most Any Command

$ man ls

This would display the help file for the command "ls".

Execute Something as SuperUser

This assumes you are in the sudoers file. You will be prompted for your password.

$ sudo <command>

To become super user permanently for your shell session, use sudo -s. Note this is dangerous and you shouldn’t do it most of the time!

Get the Current Version of Linux

$ uname -a
Linux toboe 2.6.13-15-default #1 Tue Sep 13 14:56:15 UTC 2005 i686 i686 i386 GNU/Linux

Print the Contents of a Text File

The first command here (cat) dumps the whole file, while the second command (less) lets you page through the file.

$ cat /etc/cronttab
$ less /var/log/kern.log

Analyze Disk Usage

$ df -h
/dev/hda3              14G  2.2G   12G  17% /
tmpfs                 252M   12K  252M   1% /dev/shm
/dev/hda2              87M   39M   49M  45% /boot

Find a Running Process

$ ps -ae | grep ssh
1435 ?      00:00:00 sshd
1877 ?      00:00:00 sshd
1879 ?      00:00:00 sshd

Find Devices Available (e.g. CDROM’s, HD’s, etc)

This command uses the wildcard character * to find all devices starting with ‘sd’. sd is the prefix typically given to hard disks. You could replace ‘sd’ with ‘cd’ to find cdrom drives, etc.

$ ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda5

Mount a CD/DVD ROM Drive

$ mount /dev/cdrom /media/cdrom

List all Loaded Modules

$ lsmod
Module                  Size  Used by
ext2                   52937  1
loop                   11799  0
i2c_i801                7830  0
snd_hda_codec_analog    64562  1
radeon                574812  0

Install a Package

For this example, we will install tcpdump. Note we are using sudo to run as super-user.

$ sudo apt-get update
$ sudo apt-get install tcpdump

Foreground/Background Operations

To send a running process to the background you can press CTRL-Z.

To restore it to the foreground, use ‘fq’.

[1]+  Stopped                 sudo tcpdump -i eth0
$ do-something-else
$ fg

Comments are closed