Bash Variables Cheat Sheet

For a complete list, see Bash Reference Manual – Bash Environment Variables. This is just my own memory-dump. To get the value of a variable, you can use:

echo $OLDPWD

OLDPWD
previous current directory
PWD
current directory
LANG
the language used by programs, check with locale -a for available locales. Can be set in .bash_profile with export LANG=”en_US.utf8″
LANGUAGE
the language used by programs, check with locale- a for available locales. Can be set in .bash_profile with export LANGUAGE=”en_US.utf8″
RSYNC_RSH
the shell used for rsync, usually /usr/bin/ssh

Linux Commands Cheat Sheet

There are a lot of these on the net. Why not one more? :-) I will try to keep this updated. Some commands are shell-specific (I use bash), and some are application specific, like the Apache commands.

a2enmod
enable apache module
a2dismod
disable apache module
a2ensite
enable apache site
a2dissite
disable apache site
apt-get
upgrades Debian/Ubuntu. Do sudo apt-get update first to update info, then sudo apt-get upgrade to get new version of installed files. To install a specific package, use sudo apt-get install foo, where foo is the package name.
alias
creates an alias of a command in the shell
awk
see gawk
cat
show / concatenates files
cd
change current directory
cd ~ / cd
go to home directory
cd -
go to previous directory
chgrp
changes a group of a file
chmod
changes the access rights of a file
chown
changes owner of a file
clear
clears the screen
cp
copies files
cut
cuts lines into (like @SubSet in @Forula)
date
shows the time and date
dd
convert and copy files
df
disk / partition info
dhclient
dhcp-client, use dhclient -r to release, and only dhclient to renew
dig
DNS entries
du
show directory / file sizes, use du -sh / to show total size and in “human-readable” form.
echo
prints characters
ed
text editor
emacs
text editor
exit
logs out (also CTRL-D)
fdisk
disk handling. Can list devices via fdisk -l
fg
moves a background program to the foreground
find
find files in the filesystem. Go to the directory where you want to find the file, use “find -name hosts” to find files named hosts.
ftp
file transfer utility (use scp or sftp instead)
fsck
filesystem check
fuser
shows who and what process is using a specific file or file system. Good when you want to unmount a drive. For example, fuser /media/cdrom shows the process and user that is using the cdrom and fuser -k /media/cdrom kills the associated process
gawk
reads records and fields from a file. Or words.
gpasswd
manages /etc/group
grep
searches a file for a regular expression pattern. grep -ir ‘johan’ .finds all files with the text johan, case insensitive and recursively
groupadd
adds a group
groupdel
deletes a group
gzip
compresses files
hcitool
configures BlueTooth connections. Use hcitool search to search for discoverable BlueTooth devices.
hidd
BlueTooth HID daemon. Use sudo hidd –connect XX:XX:XX:XX:XX:XX to connecto to a HID device
id
see your user id and group id’s
ifconfig
network configuration
info
show textinfo files
jobs
lists active jobs
kill
kills a process, use kill %jobno to kill a job. Some jobs may not respond to normal kill, you must use kill -KILL %jobno
less
show contents of files (backward / forward)
ln
creates a link between files
locate
find files in index
logout
logs out (also CTRL-D) or exit
ls
list files / directory
lshal
list HAL devices
lspci
list PCI devices
lsusb
list USB devices
mail
starts the mail program
man
shows manual page for a command
mkdir
creates a directory
mke2fs
formats drives
mkswap
sets up a swap partition
more
show contents of files (only forward)
mount
mounts a filesystem
mv
move or rename
nano
text editor
netstat
shows network connections
nice
handles process priority
ping
pings a host
procinfo
shows memory usage
ps
process status
pwd
print working directory
rm
removes a file
rmdir
removes a directory
passwd
sets log in passwd
route
set the ip routes
run-parts
runs all commands in a directory
scp
secure copy via ssh. Use ” and \ to escape filenames with spaces, like this: “HOWTO\ Create\ SSH\ Keys.txt”
sftp
secure file transfer (use scp if possible instead)
sed
stream editor, replaces strings in streams. Example cat test.txt | sed s/testing/helloworld/, replaces testing with helloworld in text.txt to stdout.
sensors
to read temperatures on motherboard, cpu etc.
shutdown
in SU mode, shutdowns the system, sudo shutdown -r now restarts the system.
sleep
sleeps the specified amount of time
sort
sorts the contents of a file
ssh
secure shell, use it like this: ssh username@host
su
goes to “super user mode” = root. In Ubuntu you have to set a root password first.
sudo
goes to “super user mode” on one command
swapon
activates a swap area
tar
binary to ascii encoder
telnet
telnet session, unsecure, use ssh instead.
top
monitors processes
touch
creates a new empty file or changes the date of an existing file
traceroute
traces ip hosts
tree
shows a tree of the filesystem
umount
umounts a filesystem
unalias
removes an alias
uname
shows information about the current system
unzip
decompresses ZIP files
update-rc.d
adds something to startup (Debian)
uptime
shows the uptime for the server
useradd
add a user
userdel
remove a user
usermod
modify a user
users
lists the users currently logged into the computer
vi
text editor
vmstat
shows memory usage
w
shows who are logged on and what they are doing
wait
waits for a job to finish
watch
runs a command every 2 seconds until CTRL+C
wc
word count. Also count lines
whatis
short explanation of command
whereis
shows where the specified command is and its related files
which
shows the path to the specified command
who
shows who are logged on
whoami
shows what user I am
write
sends a message to another user
xviddetect
setup video card for X
Xconfigurator
setup for X

Also see the good man-page-like command list at Oreillynet.