CS469 - Linux and Unix Administration and Networking


Basic commands you should know how to use:

Command What it does
man Read the online manual pages
ls List files
cd Change directory
cp Copy files
mv Rename / move files
rm Remove file
mkdir Make a directory
rmdir Remove empty directory
chmod Set permissions on file or files.
chown Set ownership on files.
chgrp Set group ownership on files.
touch Updates last access and modification times of files, creating new files if necessary.
getfacl Display the ACLs on a file or files
setfacl Set/update the ACLs on a file or files
ln Make links (symbolic or hard) between files.
cat Concatenate files
more/less/most Paginate output of files
grep Search for pattern in files.


kate The best Unix text editor
jove The best text-mode Unix text editor
vi The default Unix text editor for some reason
emacs A heavy-weight text-mode text editor
nano/pico A simple text editor
ne A Nice Editor

Misc file commands commands:

Command What it does
df Displays mounted file-systems and information about them
umask Set/show the default file/directory permissions creation mask.
readlink Print the value of a symbolic link.
realpath Print the real resolved path from the path given.
head Print first (10) lines in a file.
tail Print last (10) lines in a file.
zcat / zgrep / gzip Performs ops on gzipped files.
file Identifies the type of a file file is.
find Search for files in a directory hierarchy
locate Search for files indexed in a location database (much faster than find)
tree Display files and directories in a depth indented listing
sed Stream editor for filtering and transforming text.
printenv Displays the current environment.
dd Convert and copy files
init/telinit Change runlevel.
runlevel Displays the current runlevel
shutdown Halt (-h) or reboot (-h) the system.

Common scripting utilities and programs:

Command What it does
true Always succeeds (true)
false Always fails (false)
sort Sort the lines in a file.
uniq Filters out adjacent matching lines.
basename Strip the directory name [and suffix] from a filename.
dirname Strip last component from filename.
tr Translate or delete characters
tac Cat files in reverse
colrm Remove columns from a file.
cut Remove sections from each line of a file.
tee Read from stdin and write to stdout and files
env Run a program in a modified environment.
date Print or set system date and time.

Bash built-ins:

Command What it does
declare Declares variables of a specific type
let Defines integer variables, performs C like arithmetic expressions.
local Makes variables local to a function, otherwise variables are global by default.
export Makes a variable part of the environment
unset Unset the variable (default or -v) or function (-f).
alias Creates an command alias.
bg Continues a stopped process in the background.
fg Brings a job to the foreground.
jobs Lists jobs, both running and stopped.
echo Prints to the output, or a newline if strings is omitted.
printf Like the C printf function
read Reads a line of text and splits it according to IFS and assigns words the variables listed.
test Same as [...] and mostly [[...]]
source / . Reads and executes in the current shell.
ulimit Set resource limits.

Process and Library commands:

Command What it does
ps Report snapshot of current processes
pstree View processes in a tree like format
top/htop View processes continously
kill Send a signal to a process or processes.
killall Send a signal to a process or processes by name
pgrep Look up processes based on name and other attributes.
pkill Signal processes based on name and other attributes.
ldconfig Maintains links to shared libraries and updates the linker cache files
ldd Lists the shared library/objects used by a particular program.
nm lists symbols from an object.
ar Create/modify and extract from archives (.a files).
strace Trace syscalls made by a running executable.
nice Start a program at a specific niceness
renice Set the niceness of a running process.
ionice Get/Set I/O scheduling class and priority
limit/ulimit Set resource limits. (shell builtins)

File-systems and associated commands

Command What it does
fdisk Partition a disk
parted Partition a disk (supports GPT)
mkswap Initialize a swap parition or file
swapon Enable swapping on devices
swapoff Disable swapping
swaplabel Show/set swap label
mount Maps a filesystem into the directory hierarchy.
umount Removes a file-system from the directory hierarchy (un-mounts a filesystem.)
fuser Display processes (& users -u) using files, filesystems (-m) or sockets (-n).
lsof Like fuser, but more. Lists open files for all processes.
mkfs.* Make a filesystem
mke2fs Make an ext[234] filesystem.
fsck.* Check and repair a file-system
e2fsck Check and repair a Linux ext[234] filesystem.
badblocks Check device for bad blocks.
e2label Display or change the label on a ext* filesystem.
tune2fs Tune the file-system parameters on ext* file-systems.
mknod Make a device file
iostat Display CPU and disk I/O stats.
vmstat Display virtual memory statistics.
mdadm Linux MD (RAID) administration tool

User management:

Command What it does
useradd Adds a user to the system
userdel Delete a user
usermod Modify user
adduser Script wrapper to useradd
newusers Add users in bulk
chfn Change finger (gecos) information.
chsh Change default login shell.
passwd Change password for a user.
chpasswd Change passwords in bulk
chage Change password expiration for a user.
groupadd Add a group to the system
groupmod Modify a group on the system
groupdel Delete a group on the system
gpasswd Change a group password
vipw Edit passwd / shadow (-s) file
vigr Edit group / gshadow (-s) file
sudo Execute a command or start an interactive shell as another user (by default root.)
su Switch user
newgroup Switch group
sg Like newgroup but accepts a command
id Display current user/uid and group names/gid's.
groups Display current group memberships
last Display last logins in reverse order.
sac / ac System login accounting, displays login accounting (usage.)
finger/w/who/users Display who is currently logged in.

Log files:

Command What it does
klogd System daemon that logs kernel messages (usually through the syslog facility.)
dmesg Prints kernel messages to the console.
syslogd System logging daemon
logger Command line tool to log messages to the syslog facility.
logrotate Rotate/compress/mail system logs


Command What it does
quotacheck Check and update quota files.
quotaon Enable quotas on a file-system or (-a) all file-systems.
quotaoff Turn quotas off on a filesystem or (-a) all file-systems.
quota Display user or group quota
edquota Edit user/group quota
setquota Command line quota editor
warnquota Send email to users over quota
repquota Quota report
quotastats Quota statistics

MySQL / MariaDB commands:

Command What it does
mysql The MySQL/MariaDB client command
mysqldump Dumps MySQL / MariaDB databases as SQL
mysqlshow Displays a list of MySQL/ MariaDB databases

Networking commands:

Command What it does
ssh Secure shell to another computer.
scp Copy files using ssh
sftp Secure FTP client
rsync Like scp, but only copies changed files.
ssh-keygen Authentication key generation, management and conversion
ssh-copy-id Install your public key in a remote machine's authorized_keys
nc (netcat) TCP/IP swiss army knife
curl Transfer/get a URL to your local machine via the command line.
wget Non-interactive network down-loader
arp Manipulate and display ARP cache
hostname Set (requires root) or show the systems hostname
dig Another DNS lookup util
host DNS lookup util
nslookup Yet another DNS lookup util (older, almost deprecated.)
ifconfig Configure a network interface (being deprecated)
ip Show/manipulate routing, devices, policy routing and tunnels.
route Print and set routes
routel List routes
traceroute Show routes taken from host to destination.
ping Send ICMP echo's to a machine.
iptables Setup firewall rules
openssl SSL/TLS certificate and key management + misc SSL commands



  • Wildcards are NOT regular expressions
Wild-card What it represents
~ Your home directory
~username usernames home directory
* Matches zero or more characters
? Matches a single character
[...] Matches any single character enclosed in the brackets

Regular Expressions

  • Regular expressions are not wildcards


/ The root of the file-system directory (not the root account)
. The current directory
.. The parent directory
.* A "hidden" file (not normally listed unless -a option used.)
Location What goes there
/bin Programs that required at boot time
/boot Location of kernel and boot loader files
/dev Location of the devices files
/etc System wide configuration files
/lib* Program libraries needed by programs at boot time
/proc The process and system configuration pseudo-file-system
/run The runtime files for system services
/sbin Programs (usually used by the administrator) needed at boot time
/sys System information pseudo-filesystem
/tmp Temporary files not guaranteed to be preserved across reboots
/usr Read only data not needed at boot time
/usr/bin Most user programs
/usr/lib* Most of the program libraries
/usr/local Tertiary hierarchy for local system additions
/usr/sbin non-essential system programs (daemons)
/usr/share Shared data
/var Variable data that changes during run-time
/var/log Log files (syslogd and klogd)
/var/mail User mailboxes
/var/tmp Temporary files that are guaranteed to be preserved across reboots


  • Invocation: #!/bin/bash
  • chmod a+x ... to make executable
  • Pipelines: a | b, a |& b, ! a
  • Command lists: a ; b, a & b, a && b, a || b
  • if a; then echo "a was successful"; fi
  • if ! a; then echo "a failed"; fi
  • Compound commands:
    • ( commands ) (subshell)
    • { commands } (local shell)
    • (( C-expression )) (as a command, evaluates to true/false)
    • [ test-expression ]
    • [[ test-expression ]]
  • I/O redirections:
    • < file - reads file as input
    • > file - outputs to file, overwriting it
    • >> file - Appends to file
    • &>, &>> - Outputs/appends both stdout/stderr to file
    • Heredocs: <<, <<< string, < <( command )
  • Quoting:
    • single quotes - no expansions
    • double quotes - variable expansions
  • Bash data types: strings, integers, arrays and associative arrays
  • Variable expansions:
    • Basic expansion: $foo, ${foo}
    • Array size: ${#foo[*]}
    • Default: ${foo:-default}
    • $(( expression ))
  • Command expansion:
    • $( expression )
    • back-ticks
  • Functions - how to define them, how to make variables local
  • Loops:
    • while program; do statements; done
    • for variable; do statements; done - iterates over the positional parameters
    • for variable in words; do statements; done - iterates over words
    • for (( init ; test ; inc )) { statements } - C style loop
  • Conditional:
    • if command ; then statements ; fi
    • if command ; then statements ; else statements ; fi
    • if command ; then statements ; elif statements ; else statements ; fi
Bash special var What it does
$? Status of the last command run
$# Number of positional parameters
$1, $2... The positional parameters (the command line arguments )
$*, $@ Expands to the positional parameters ($1 and up )
IFS The internal field separator
RANDOM Random number from 0 to 32767
PATH The colon delimited string of file-system paths to search for programs in
  • for var in $*; do .. done - Iterates over the positional parameters from $1 up.

Processes and threads

State What it represents
R Running: the process is executing in normal user-space.
S Interruptible Sleep: The process has either given up it's time slice or been pre-empted by the kernel into giving up it's time.
D Uninterruptible Sleep: The process is waiting on I/O to complete, usually means it is waiting for a kernel system call to return.
T Stopped: The process execution has been temporarily suspended by a job control signal (SIGSTOP/SIGTSTP) until it is continued (via SIGCONT)
X/Z Dead or Zombie: The process has completed and has either been reaped (X - should never actually be seen) or is waiting to be reaped (Z).
Memory How much memory the process is using (VSZ - Virtual Size, RSS - Resident Set Size - non-swapped heap+stack, Size - Heap+Stack
FS info root FS, cwd, umask, etc
I/O Descriptors Files, IPC, network objects
Namespace Hierarchy of mounted file-systems
Signal Handlers + Signal dispositions
Credentials Identifying info about process and parents
Scheduling Priority Niceness: -19 (highest) - 20 (lowest)
Resource Limits
Processor affinity How closely tied to specific CPUs/Memory
Additional meta info Start / CPU time / Current state / CPU running on


  • Path resolution
  • Inode information about files (Owner uid/gid, mode (permissions), file-type, size, times (atime, ctime, mtime))
  • What each part of 'ls -l' output means
    • file types: d, -, l
  • ACLs
  • Regular expressions
  • Signals SIGSTOP, SIGKILL cannot be caught blocked or ignored.
  • Process resource limits