Ondřej Plátek Blog
PhD candidate@UFAL, Prague. LLM & TTS evaluation. Engineer. Researcher. Speaker. Father.

Week 2, Intro to Unix lab 2016

Content

  • Thanks for PR (pull requests)
    • Keep contributing! Not only spelling fixes but also your suggestions and interesting literature are very welcome!
  • Homework recap
    • Instructions, intentions, problems and scoring
    • parameters man -S1 man and man -S 1 man
    • Comments # this is a comment - it does nothing
    • Debugging set +x, set -x - Try it at home! What does it do?
    • copying out scripts from lab scp, using ssh -Y, or winscp
  • tr presentation by Hlupaco
  • Basic commands: touch, echo, cp, mv, rm, mkdir,
    • relative paths ., .., ../..
    • links (with relative paths and pitfalls) ., ln -s
    • important standard paths: /bin, /var, /etc, /usr, ...
  • cd, cd -, cd /path/to/directory, cd .. # go to parent directory, cd ../.. # go two directories up
  • man and less. Navigation (j, k, Ctrl+k, Ctrl+p, /, q)
    • apropos and man -k
    • --help parameter
  • pipes, stdin, stdout
    • redirecting file to stdin
      • by cat my_file | head -n 2
      • by head -n 2 < my_file
      • Do not confuse with using the file name as argument!
        • head -n 2 my_file
    • redirecting to file, e.g. cat my_file.txt > copy_of_the_file.txt
    • redirecting error output to file ls -l not_existing_file.txt 2> error > attribute_of_file.txt
    • swapping stderr and stdout
      • useful e.g for pipes ls -a not_existing_file.txt 2>&1 > attribute_of_file.txt | tee error
      • useful for printing to stderr echo "printing to stderr" 1>&2"
  • script arguments
1
2
3
4
5
6
7
8
9
10
11
12
13
# content of script test.sh

# printing help to stderr
echo "Usage: $0 [arg1 ...]" 1>&2
echo All arguments
echo $@

for arg in $@; do
    echo $arg
done

echo First argument
echo $1
  • next time
    • chmod, chown and ls
    • Intro to vi and vim

Homework

(3 points) Imagine you have three files text, table1, table2.

  • The file text contains free text.
  • The file table1 contains sequence of characters which should be replaced from the file text on single row.
  • The file table2 contains sequence of characters which should be replaced to based on the file text and the sequence in file table1 on single row.
  • Note: Strange characters like ’*’, new line (LF), ‘?’ or space may appear in all three files.
  • The result save into file results.

Bonus

  • (2 points) Prepare a short presentation (in Czech) about cut command
    • Explain to others how it can be used
      • Syntax and how to read the manual page
      • Use with echo and pipes (Pipes will be introduced next time).
      • Prepare at least three examples how it can be used. Use standard files such as /etc/passwd
  • (2 points) Man - time exercise from first week
  • (Easy Vim understanding) Go through Vimtutorl by running vimtutor from shell