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

Week 3, Intro to Unix lab 2016

Content

  • How to recognize bashism?
    • Colours in terminal are not portable but are fun:
    • What does this command do?
      • curl http://wttr.in/Prague
      • wget http://wttr.in/Prague -O - | tee /tmp/wheather
  • quick recap - redirection
  • presentation cut
  • Practice teamwork!
    1. create script documented_list.sh
    • at the beginning prepare dummy data
    • on the dummy data illustrate behaviour of ls options: -d, -i, -R, -r, -a, -A, -t
      1. create script test_inode.sh
    • create file /tmp/YOUR_LOGIN/a using two commands and pipe
    • create symlink to the file in your home directory
    • list inode numbers of the target and symlink file
    • create file /tmp/YOUR_LOGIN/b
    • move it to your home directory but list the inode number before and after
    • create file /tmp/YOUR_LOGIN/c
    • copy the file to home and list inode again
    • create file /tmp/YOUR_LOGIN/d
    • create hardlink in the home directory
    • write a comment describing the output
      1. create file and directory with permissions 000, 600, 700, 644, 755 what is the behaviour?
    • what is the corresponding rwxs representations?
      1. create script forgery_YOURLOGIN.sh
    • Wait for explaining chown or read the man page
    • Ask your colleague to log to the same computer in the lab
    • change the owner of the forgery script to user user specified on the first argument
      • use your colleague name
    • write your colleague also a message that he will be accused of writing malicious scripts
    • what was the problem?
      1. create a directory responses_YY-MM-DD-HH-MM/raw_responses for time stamping, make sure that the command has exit status 0.

Homework

  • create backup script backup.sh
    • the script takes two arguments: a file or a directory and a target directory
    • target directory may not exists, but it can
    • file or directory from first argument is copied to the target directory
    • change the permissions of the files in the target, so it is readable to everyone
      • not recursively, just the files directly in the target directory
    • change the permissions of the target directory and its subdirectories so everyone is able to browse it but not rename it, write to it, delete files from it
      • not recursively, just the direct subdirectories of the target directory
    • write the target directory size (in KB/MB/GB) in to stderr
    • demonstrate the usage of the script by backing up all dotfiles (files starting with dot) in your home directory to target directory ~/settings_YY-MM-DD
      • hints:
        • YY-MM-DD is a template for date format. For date March 11th 2016 it should look like 16-03-11. Have a look at the date command.
        • For repeated usage you have to “unlock” the target directory for writing again
        • For-loop may be useful for using the script multiple times