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, join, ls, mkdir, paste, pwd, rev, rm, rmdir, scp, sort, tac, tail, tar, test, touch, tr, uniq, 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 containg given expression (either searches for a normal string with -F or uses a full-fledged regular expression (regex)).
man 1 grep
(man7.org,
linux.die.net).
grep -F 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
join: join (merge) sorted files on a common column
man 1 join
(man7.org,
linux.die.net).
echo -e "alpha 4\nbravo 3\ncharlie 5" >points.txt echo -e "alpha blue\nbravo red\ncharlie green" >colors.txt join colors.txt points.txt
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
rev: reverse characters on each line
man 1 rev
(man7.org,
linux.die.net) (Linux-only extension, not available on all Unix-like systems).
rev /etc/passwd echo olleH | rev
On systems lacking rev one can use the following ugly hack:
sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'.
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
scp: (Securely) Copy files across different machines
man 1 scp
(man7.org,
linux.die.net).
scp local.file remote_user@remote_machine scp local.file remote_user@remote_machine:remote_destination scp remote_user@remote_machine:remote_file local.destination
sort: sort lines
man 1 sort
(man7.org,
linux.die.net).
sort /etc/group sort -n -t: -k3 /etc/passwd
tac: concatenate and print files in reverse
man 1 tac
(man7.org,
linux.die.net) (Linux-only extension, not available on all Unix-like systems).
tac /etc/passwd ( echo Alpha; echo Bravo ) | tac
tac can be replaced with tail -r, and it seems that
-r will be soon on all POSIX-compliant systems.
Another option (but much less readable) is to
use sed '1!x;H;1h;$!d;g'.
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
tar: archiving utility
man 1 tar
(man7.org,
linux.die.net).
tar -cf file.tar directory/ tar -czf file.tar.gz directory/ tar -xf file.tar tar -xzf file.tar.gz
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 echo '15 16 17' | tr -s ' ' '+'
uniq: find unique or repeated lines (or count them)
man 1 uniq
(man7.org,
linux.die.net).
getent passwd | cut -d : -f 7 | sort | uniq getent passwd | cut -d : -f 7 | sort | uniq -c
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