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)

Manual page: man 1 bc (also at man7.org or linux.die.net).

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

cat: concatenate and print files

Manual page: man 1 cat (also at man7.org or linux.die.net).

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

cd: change the current (working) directory

Manual page: man 1p cd (also at man7.org or linux.die.net).

cd
cd /etc

cp: copy files and directories

Manual page: man 1 cp (also at man7.org or linux.die.net).

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

cut: print parts of lines

Manual page: man 1 cut (also at man7.org or linux.die.net).

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

echo: write arguments to standard output

Manual page: man 1 echo (also at man7.org or linux.die.net).

echo
echo -n Hello
echo Printing Hello World to screen

grep: print lines matching regular expression (regex)

Manual page: man 1 grep (also at man7.org or linux.die.net).

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

head: print beginning of files

Manual page: man 1 head (also at man7.org or linux.die.net).

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

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

Manual page: man 1 ls (also at man7.org or linux.die.net).

ls
ls /etc
ls /proc/1/fd

mkdir: create (make) directories

Manual page: man 1 mkdir (also at man7.org or linux.die.net).

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

paste: merge lines of files together

Manual page: man 1 paste (also at man7.org or linux.die.net).

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

Manual page: man 1 pwd (also at man7.org or linux.die.net).

pwd

rm: remove files and directories

Manual page: man 1 rm (also at man7.org or linux.die.net).

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

rmdir: remove directories

Manual page: man 1 rmdir (also at man7.org or linux.die.net).

rmdir dir1
rmdir /etc
rmdir -p dir1/dir2

sort: sort lines

Manual page: man 1 sort (also at man7.org or linux.die.net).

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

tail: print the last part of file(s)

Manual page: man 1 tail (also at man7.org or linux.die.net).

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

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

Manual page: man 1 test (also at man7.org or linux.die.net).

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

Manual page: man 1 touch (also at man7.org or linux.die.net).

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

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

Manual page: man 1 tr (also at man7.org or linux.die.net).

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

wc: count words, lines and bytes in a file

Manual page: man 1 wc (also at man7.org or linux.die.net).

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