Skip to content

Instantly share code, notes, and snippets.

@deep9
Forked from bajeluk/ucl_unix_test.md
Created March 12, 2016 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deep9/1e7b07ec73480d650a3a to your computer and use it in GitHub Desktop.
Save deep9/1e7b07ec73480d650a3a to your computer and use it in GitHub Desktop.

Commands for UCL Linux test (NOS Spring 2016)

Quite nice introduction to Bash

http://www.tutorialspoint.com/unix/index.htm

Set of solved examples

Libor Forst: Shell v příkladech. Matfyzpress 2010. ISBN 978-80-7378-152-1

Especially these examples:

1.1 - 1.9, 1.10 - 1.13, 1.15 - 1.17; 2.1 - 2.6, 2.12 - 2.17; 3 - ed ne, sed ano 3.1 - 3.7, 3.12; 4.1, 4.3, 4.4, 4.6, 4.12, 4.22

http://www.mff.cuni.cz/fakulta/mfp/download/books/forst_-_shell_v_prikladech.pdf (not anymore functional :( )

Filesystem

ls -l -a -d -t -1 (-R -h)
rm, mv, rmdir, mkdir
touch -d -r
cp -r
df -h
pwd

Text

echo, head, tail, wc -l
cat, less, more, tr -s

sed -n (and sed commands s, p)
  - sed 's/REGEXP/REPLACEMENT/'
    - REGEXP: . * \+ [a-zA-Z0-9] [^abc] \(...\) \| ^ $
    - REPLACEMENT: \1, \2, ...
  - sed -n '1,4p'
grep -c -n
cut -d -f
read (and $IFS-variable setting)
sort -n -t -k
uniq
printf

Network

ifconfig -a
traceroute / tracepath
ping
/etc/resolv.conf
/etc/hosts

User and file rights

chmod
chown
newgrp
passwd
/etc/passwd
/etc/group

Variables and arithmetics

A=value
(( ... ))
A=$(( ... ))
{3..10}             # Bash extension

Shell internals

Quoting

'...'
"...$VARIABLE..."
`command`

Redirecting

>, >>, <, | (pipe)

Control flow

for COMMAND; do ... done
  - for ((i;i<10;i++)); do ...  # Bash extension
  - for fname in *.cpp; do ...
while COMMAND; do ... done
  - while read p1 p2 ...; do ...
if COMMAND; then ... else ... fi
  - if ((A<10)); then ...       # Bash extension
  - if [ -e $FILE ]; then ...
exit
test / [ ... ]

Shell file expansion

*, ?, [a-z]

Script basics

#!/bin/bash
...
execute permissions

Script variables

$0, $1, ..., $9
$#, $*, $$, $!, $?
shift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment