basic commands

system info
cat /etc/issueshow linux distribution name cat /proc/version show kernel version, etc.. cat /proc/cpuinfo processor information cat /etc/passwd list users on the system cat /etc/services list reserved ports date display system time date --date="-5 days" +%Y%m%d get date in the past & format output hostname show current machine hostname free show memory usage uptime show time since the last boot uname -a show information about system
hardware info
lspci list all PCI devices lshw list all hardware lshw -class network list network hardware dmidecode List all hardware data from BIOS
users
whoami show current username w / who show logged in users finger user_name System info about user write somuser Write a message to a logged in user last show last logins on your system lastb ("=last bad") show unsuccessful login attempts
drives
df -h show harddrive usage mount show mount points fdisk -l show harddrive and partition info hdparm -t /dev/hdX show HD speed (~100MB/s is normal) hdparm -iI /dev/hdX Harddrive information
files
pwd display current path stat $filename show filesystem info about file file $filename show file type information time $command measure execution time of command rename 's/\.png$/.jpg/' * batch rename files du size of current directory du --max-depth=1 list sizes of direct subdirs tail -f /var/log/some watch log file changes
console commands debugging
which [cmd] show path of command [cmd] ldd [path-to-cmd] show libraries used by [cmd]
package management
apt-cache search $regexp search available packages for $regexp apt-get install [pkg] install package named [pkg]
send mails
mail -s "mail subject" some@one.com send email interactively. send = CTRL+D mail -s "mail subject" some@one.com < mailbody.txt Send file contents as email echo "bodytext" | mail -s "mail subject" some@one.com send mail, without need for a file
environment variables
PATH=some/new/path:$PATH Add something to the PATH variable

bash

keyboard commands on the bash console. you can also use them inside a screen session
basic bash commands
cd $dir change into directory history show last executed commands !$nr execute command nr $nr from history
keyboard shortcuts
cursor up / down scroll through last commands SHIFT + page up / down view console history CTRL + A jump to first character in line CTRL + E jump to last character in line CTRL + K cut (&memorize) from cursor to end of line CTRL + U cut (&memorize) from cursor to start of line CTRL + Y paste the recently memorized content CTRL + L clear screen CTRL + D quit terminal session (same as entering "exit") CTRL + S stop console scrolling CTRL + Q continue console scrolling

grep

grep [options] searchstring [file(s)] search file(s) and show all lines that contain the searchstring. If searching in more than one file, also shows filename. grep can also accept input from STDIN.
examples
grep string *.html -r find string in html files (recursively), show filenames and lines grep -P "$regexp" *.sh show $regexp matches in .sh files in current dir ls | grep string show all filenames that contain string
options
grep -r find recursively in subdirs grep -o show only the found string / the matching pattern grep -i case insensitive grep -v invert match grep -P perl regular expression matching

find

find [path] [criteria] [action] all files in path + its subdirectories, if they match criteria, apply action. Default action is "print path+filename". Default path is "current directory".
search parameters
-name whatever # search filename case sensitive -iname whatever # filename case insensitive -ipath whatever # search path case insensitive -regex / -iregex # regular expression search -mtime +7 # modified more than 7 days ago -size +10M # files that are >10MB -size -1G # file size less than 1GB -user tom # files that belong to user tom -type f # find only files -type d # find only directories -type l # find only symbolic links
actions
-exec tar rvf arch.tar '{}' \;execute tar command for all files, execute in current dir -execdir execute in directory of file -delete delete matched files

processes

process basics
ps fauxw list process tree top show processes with most resource usage htop show processes with colors and fancyness strace -p $pid see commands executed by $pid lsof -n -P |grep "*" list used ports
netstat
netstat -lpnv list all listening applications -l only listening sockets -p show process names and ids -n numeric, dont resolve hostnames -v verbose netstat -tulpen nice list without the clutter

sed

add or replace strings in files or STDOUT
examples
sed 's/some/other/' file replace some with other in file, print result sed -r 's/perl-regex/replacement/' file replace with perl regex

vim

Vim is a text editor like EMACS. VIM has it's own poster :)
use vim for prettifying files
:1,$!xmllint --format --recover - 2>/dev/null Prettify XML :%!python -m json.tool Prettify JSON

networking

Remeber to use sudo for commands like ifconfig, nmap or tcpdump.
network information and configuration
lspci | egrep -i --color 'network|ethernet' show network hardware cat /proc/net/dev show network traffic ifconfig # show network hardware config ifconfig eth0# show network interface infos ifconfig eth0 down # disable interface eth0 ifconfig eth0 up # enable interface eth0
scan local network
iwlist scan # show wireless access points nmap -sn 192.168.100.0/24 # List other computers on the network nmap -F -O -sV 192.168.100.198 # Show details of one computer
check network traffic
tcpdump -D # list available devices tcpdump -i wlan0 # show 68 bytes (=default) of all packets tcpdump -i wlan0 -s 0# show all traffic tcpdump -i wlan0 -s 0 -w out.dump tcp port 80 # log full traffic on port 80 to file
ssh related
ssh login@machine -L 1521:machine:1521 # tunnel local port 1521 to other machines port 1521 scp -l 800 hugefile.tgz example.com:~/ # Limit SCP upload speed to 800kbit/sec (= ~100kByte/sec)

file transfer

wget
wget "ftp://user:pass@ftp.ähh.com/*" -b -r # download all files from ftp (-b = in background, -r recursively) wget "ftp://ftp.ähh.com:21/somedir/*" -r --user=user --password=pass # some versions need credentials as parameters
scp
scp ./* user@server.net:/sub/dir/ # upload content of current dir scp user@server.net:/var/lib/ibdata1 test # download remote file ibdat to local file test
special characters in passwords
unsafe characters in password/username can usually be url-encoded (="% + hex-value of the ascii code"). See this table for the most common unsafe characters:

Parameters

'!'(%21)
'%'(%25)
':'(%3A)
'@'(%40)

screen

screen is a terminal-multiplexer. you can use it to save your bash or ssh sessions, keep sessions running on the server if you log out, and much more.
manage screen sessions
screen -S sessionname start session (with optional name "sessionname") screen -ls list all my screens screen -r [sessionname] reattach a running screen to current terminal
keyboard commands inside screen
CTRL+A d deatach, but keep screen running CTRL+A c create new window CTRL+A n go to next window in current screen CTRL+A p go to previous window in current screen CTRL+A ESC enter "copy mode"
inside "copy mode": cursormove around enter start and stop selection, copy to buffer 0jump to first column $jump to end of line page upview the console history ESCexit copy mode
CTRL+A ]paste buffer content CTRL+d close current screen window, or close complete screen if it was the last window

tmux

tmux is a modern terminal-multiplexer, it replaces screen. Additionally it can split windows.
basic usage
tmux ls list running sessions tmux new -s session-name create new named session tmux a [-t session-name] resume session-name [can be name or number]
keyboard commands inside a tmux session
CTRL+b ? get help CTRL+b s list sessions CTRL+b $ rename the current session CTRL+b d detach from the current session CTRL+b % split window vertically CTRL+b " split window horizontally CTRL+b z toggle fullscreen current split CTRL+b cursor go to split window CTRL+b [ enter "copy mode"
inside "copy mode": cursormove around CTRL+SPACE visual selection ALT+w copy selection ESCexit copy mode
CTRL+b ]paste selection

tar

tar [options]f filename.tar dir copy all files from directory "dir" into archive file "filename.tar".
examples
tar cf a.tar dir # create archive a.tar with all files from dir (+subdirs) tar czf a.tgz dir archive and gzip files tar czf a.tgz --newer-mtime 02/25/2025 dir archive all files that were created or modified after 25.02.2025 tar czf a.tgz --exclude="temp/*" --exclude="bak/*" dir except files in temp or bak dirs tar tzf a.tgz print a list of all files in a.tgz tar -xzf a.tgz extract, keep directory structure

gzip / bzip2

gzip [options] filename Compress or uncompress files. gzip and bzip2 have almost same syntax.
examples
gzip $file compress $file into $file.gz, remove $file gzip -d $file.gz uncompress $file.gz into $file gzip -dc $file | moreuncompress $file to STDOUT

awk

awk -F"\t" '{print $3}' filename Print third column of tab separated file (-F specify separator char) cat access_log | awk '{urls[$1]++ } END {for (a in urls) {printf ("%50s\n", a ) }}' print number of occurrence for all urls in first column of access_log ls dir | awk '{print "mv "$1" "$1".new"}' | sh rename files to ".new" ls -l *old* | awk '{print "mv "$1" "$1}' | sed s/old/new/2 | sh rename inside of filename kill `ps auxw | grep $processname | egrep -v grep | awk '{print $2}'` kill all processes with name $processname

advanced exaples

for i in `seq 20 10 100`; do echo $i; done print the numbers from 20 to 100 in steps of 10 perl -e 'while(true){print (`clear; ps aux|grep $processname|grep -v grep`); sleep (1); }' constantly updated list of processes named $processname df -P | awk '{print $5}'| tr -d '%' | grep '[0-9]' | xargs -I {} sh -c 'if \[ 0 -lt {} \];then echo ne disk is {}% full:;df; fi' | mail -E -s 'disk full' some@user.com use this cronjob to send you an email you when the disk is full