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 (man7.org, linux.die.net).

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

cat: concatenate and print files

man 1 cat (man7.org, linux.die.net).

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

cd: change the current (working) directory

man 1p cd (man7.org, linux.die.net).

cd
cd /etc

cp: copy files and directories

man 1 cp (man7.org, linux.die.net).

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

cut: print parts of lines

man 1 cut (man7.org, linux.die.net).

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

echo: write arguments to standard output

man 1 echo (man7.org, linux.die.net).

echo
echo -n Hello
echo Printing Hello World to screen

grep: print lines matching regular expression (regex)

man 1 grep (man7.org, 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

man 1 head (man7.org, linux.die.net).

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

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

man 1 ls (man7.org, linux.die.net).

ls
ls /etc
ls /proc/1/fd

mkdir: create (make) directories

man 1 mkdir (man7.org, linux.die.net).

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

paste: merge lines of files together

man 1 paste (man7.org, 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

man 1 pwd (man7.org, linux.die.net).

pwd

rm: remove files and directories

man 1 rm (man7.org, linux.die.net).

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

rmdir: remove directories

man 1 rmdir (man7.org, linux.die.net).

rmdir dir1
rmdir /etc
rmdir -p dir1/dir2

sort: sort lines

man 1 sort (man7.org, linux.die.net).

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

tail: print the last part of file(s)

man 1 tail (man7.org, 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 [)

man 1 test (man7.org, 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

man 1 touch (man7.org, linux.die.net).

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

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

man 1 tr (man7.org, 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

man 1 wc (man7.org, linux.die.net).

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