Useful linux commands and the like

What follows are linux commands and the like that I have found useful over the years, recorded here as a kind-of quick reference.

Users & Groups

Change a users username
usermod --login <new-username> <current-username>
Change a users home directory
usermod --home <new-user-dir> <username>
Move a users home directory
usermod --home <new-user-dir> --move-home <username>
Change a users username and move their home directory
usermod --home <new-user-dir> --login <new-username> --move-home <current-username>
Add a user to a group
gpasswd -a <username> <group>
Change a group name
groupmod --new-name <new-group-name> <current-group-name>

System information

Benchmark Hard-drive
hdparm -t /dev/<drive>
List all block devices (disks and such)
lsblk
List all [PCI-bus-connected] hardware
lspci
List linux release name and version
lsb_release -a
List network interfaces and their addresses
ip addr show
List the kernel type and version
uname -a
List all systemd services (also called "units")
systemctl --no-page list-unit-files

Gentoo-specific commands

Clean out old distfiles
eclean-dist -i -v
Monitor DistCC from the terminal
DISTCC_DIR="/var/tmp/portage/.distcc" distccmon-text 1
Package [Gentoo] system for binary distribution
cd /var/db/pkg/; for i in */*; do quickpkg --include-config=y =$i; done
Quickpackage a [Gentoo] LiveDVD (tried with Gentoo x86 10.1 LiveDVD)
mount /dev/sda3 /mnt/gentoo
mount --bind /mnt/gentoo/usr/portage/packages/ /usr/portage/packages/
mkdir /mnt/gentoo/foo
cp -R /var/db/ /mnt/gentoo/foo/
mount --bind /mnt/gentoo/foo/db/ /var/db/
cd /var/db/pkg/
for i in */*; do quickpkg --include-config=y =$i; done
Find old/outdated entries in /etc/portage/package.*
eix -tT test
A more verbose version of the above command
eix-test-obsolete
Remove revdep-rebuild temp files
rm /root/.revdep-rebuild*.?_*
See what package is emerge-ing
qlop -c
Similar to above but with an ETA
genlop -c
List previous emerge times for a package
qlop -gH <package-name>
Calculate merge time for a package (based upon previous emerge times)
qlop -tH <package-name>
Get the name of the package that a file belongs to
qfile /filename/with/path
List files that a package owns
qlist <package-name>
List packages that depend in a given package
equery depends <package-name>
List packages that a given package depends upon for building
qdepends <package-name>

Ubuntu-specific commands

Search for package
apt-cache search <name>
Find out if package is installed
apt-cache policy <package-name>
Fix all broken packages
apt-get update --fix-missing
dpkg --configure -a
apt-get install -f

Other

Find the location of a program
which <program-name>
Another way to find a program
whereis <program-name>
Kill all instances of a program
kill $(pgrep <program-name>)
Dump a stream to a file with MPlayer
mplayer -noframedrop -dumpfile out.rm -dumpstream rtsp://the-url.com/video.rm
Mount a CD/DVD image
mount -o loop some-disk-image.iso
Show the free space on mounted filesystems
df -h
Show the size the current folder (this may take a while if there are lots of files/sub-folders)
du -sh
Resume stopped jobs [Ctrl+Z] to foreground
fg
Resume stopped jobs [Ctrl+Z] to background
bg
List all stopped jobs
jobs
Make a BZip2 tarball
tar -cvjf archive.tar.bz2 /dir/or/filename/to/add
Change permissions on folders only
find <path> -type d -exec chmod <permissions> {} \;
Make an array of file names in bash
IFS=$'\n'; foo=($(ls <dir-to-get-list-from>)); IFS=$' '
Change kernel swappiness (default is 60)
sysctl -w vm.swappiness=10
echo "vm.swappiness = 10" >> /etc/sysctl.conf
X11VNC screen sharing (use a VNC client to view)
x11vnc -noxdamage
Create a VirtualBox HDD file pointing to a USB storage device
VBoxManage internalcommands createrawvmdk -filename /some/location/usbdisk.vmdk -rawdisk /dev/<device>
Show all open TCP and UDP sockets
netstat -avtup
Watch all open TCP and UDP sockets with 1 second updates
watch -d -n1 'netstat -avtup'