This page contains an overview of commands that we will be using during the labs. It is supposed to be used as a starting point: when you know what to do but do not know which command solves this task. Use the provided links or your local manpage to learn more about the command.

The provided examples shall work out-of-the box on any reasonably recent GNU/Linux machine.

Commands: bc, cat, cd, cp, cut, echo, grep, head, ls, mkdir, paste, pwd, rm, rmdir, sort, tail, test, touch, tr, wc.

bc: arithmetic language processor (calculator)

man 1 bc (,

echo "for (x=0; x<10; x++) {random();}" | bc
bc ~/arithmetic-computation

cat: concatenate and print files

man 1 cat (,

cat /etc/passwd
cat /etc/passwd - /etc/group

cd: change the current (working) directory

man 1p cd (,

cd /etc

cp: copy files and directories

man 1 cp (,

cp /etc/passwd .
cp /etc/passwd ~/passwords.backup
cp -r /etc/default defaults_copy

cut: print parts of lines

man 1 cut (,

cut -d: -f 1,5-7 /etc/passwd

echo: write arguments to standard output

man 1 echo (,

echo -n Hello
echo Printing Hello World to screen

grep: print lines matching regular expression (regex)

man 1 grep (,

grep system /etc/passwd
grep --color=auto system /etc/passwd
grep ':[0-9][0-9][0-9]:' /etc/passwd

head: print beginning of files

man 1 head (,

head /etc/passwd
head -n2 /etc/passwd /etc/group

ls: list directory contents (files, their modification time etc.)

man 1 ls (,

ls /etc
ls /proc/1/fd

mkdir: create (make) directories

man 1 mkdir (,

mkdir dir1 dir2 dir3
mkdir -p dir1/dir2/dir3

paste: merge lines of files together

man 1 paste (,

paste /etc/passwd /etc/group
paste -d+ /etc/passwd/ /etc/group
cut -d: -f 3 /etc/passwd | paste -s -d+

pwd: print current (working) directory

man 1 pwd (,


rm: remove files and directories

man 1 rm (,

rm ~/passwords.backup
rm -r dir1
rm /proc/1/status

rmdir: remove directories

man 1 rmdir (,

rmdir dir1
rmdir /etc
rmdir -p dir1/dir2

sort: sort lines

man 1 sort (,

sort /etc/group
sort -n -t: -k3 /etc/passwd

tail: print the last part of file(s)

man 1 tail (,

tail -n 5 /etc/passwd /etc/shadow
tail -q -f /etc/group

test: compare values, check file types, useful for conditions (also [)

man 1 test (,

test 5 -gt 2; echo $?
test 2 -gt 5; echo $?
[ 5 -gt 2
[ 5 -gt 2 ]; echo $?
test -f /etc/passwd

touch: change (updates) file timestamps, also creates new file

man 1 touch (,

touch ~/touch.example.txt
touch ~/.bashrc
touch /etc/passwd

tr: translate (replace) or remove characters (letters)

man 1 tr (,

tr ':' ' ' </etc/passwd
tr -d '/' </etc/passwd
tr 'a-z' 'A-Z' </etc/passwd

wc: count words, lines and bytes in a file

man 1 wc (,

wc </etc/passwd
wc /etc/passwd
wc -l </etc/passwd