A GNU/Linux Cheatsheet
John Gabriele, 2014-09-15
http://www.unexpected-vortices.com/

Note: a number of these commands must be run as root, otherwise they will silently return with no output.

Using the Terminal

Alt-F keys switch you between virtual terminals.

Shift-{PgUp,PgDn} for paging up and down.

Services

/etc/init.d/{SERVICE-NAME} {start|stop|restart}
# or
service {SERVICE-NAME} {start|stop|restart}

Note that systemd provides servicectl, rather than service, but on most OS’s service will be smart enough to do the right thing whether your service is managed by rc-init or systemd.

Network

The ip command (provided by the iproute2 project) has replaced: ifconfig, arp, netstat, mii-tool, rarp, nameif, and route (which are all in the net-tools package).

The Debian package for iproute2 is iproute.

ip

supports multiple subcommands, which take commands themselves, ex:

ip addr show
ip link show
ip route show
ifup/ifdown
bring a given interface up/down
ss
dump socket stats. Ex.: ss -tupl
ethtool
apt-get install this.
tracepath
Like traceroute, but doesn’t require root and supports fewer options.
mtr
Matt’s traceroute
ping
{pass}
arping
ARP request
tcpdump
todo
iftop

like top, but for network traffic. See also top, iotop.

For name resolution, use dig (which replaces nslookup).

Hard Disk

fdisk
Ex.: fdisk -l
hdparm
Ex.: hdparm -I /dev/sda
parted
Alt to fdisk. Ex.: parted -i
smartctl
To get this, apt-get install smartmontools.
blkid
Shows devices and their UUIDs.
badblocks
Low-level block scanner. On large drives, may take a while to run.
fsck
File-system check. Requires that the partition is formatted.

Also:

mount
cat /etc/mount
cat /etc/fstab

Package Management

dpkg -L {pkg-name}  # List files provided by this pkg

# Search for filenames provided by all installed pkgs.
dpkg -S {some-str}

To see what files a not-yet-installed package provides:

# install apt-file, if necessary
apt-file update
apt-file list {package-name}

Or look in http://packages.debian.org/{DISTRO-NAME}/all/{PACKAGE-NAME}/filelist.

Or, if you have the .deb file: dpkg -c <pkg-name.deb>

Files, Dirs, IO

lsof
list open files
fuser
todo
iotop
like top, but for IO

Hardware Info

lspci
lshw  # Has option for abbreviated output.
ipmi-sensors
uname -a

Processes and Memory Usage

free -h   # see memory usage
top       # table of processes
htop      # interactive top
vmstat

RAID

# Takes args like "/c0".
/opt/3ware/bin/tw_cli.x86_64

Misc

watch some-command
tail -f some-file