Unix ja shell-ohjelmointi 2001, demo 3 Unix ja shell-ohjelmointi 2001, demo 3 (7.2.2001)

  1. How can you

    1. find all files under /var that are either world-writable, or group-writable with group users or staff?
    2. remove all files under $HOME/tmp that haven't been used for a week, except anything under subdirectories named keep should be left intact?
    3. copy a directory tree so that the entire tree structure is copied except files ending .o or named a.out or core are not copied?

  2. Write a script

    paloittele [-i input ] [-s string ] n1...

    that splits given file or stdin into pieces called string .1, string .2 etc (default x.1, x.2...) so that the first file has first n1 lines etc, and the last whatever is left over. E.g.,

    paloittele -i kalat -s k 5 6 5

    would create files k.1 with lines 1-5 from kalat, k.2 with lines 6-11, k.3 lines 12-16 and k.4 the rest.

  3. Write a script

    putkita [-i input ] [-o output ] command...

    that executes given commands as a pipeline. E.g.,

    putkita -i kalat -o fisut sort 'tr a-z A-Z' 'paste - -'

    should be equivalent with

    sort <kalat | tr a-z A-Z | paste - - >fisut

    You can assume there's less than 10 commands.

  4. We want to compare too password files (Unix /etc/passwd-format) and search for login names that appear in both but have different uid or name field. Write a script that

    1. outputs lines with same login name but different uid or name (entire lines) next to each other (and omits other lines)
    2. outputs such duplicates on one line in format loginname, uid1, nimi1, uid2, nimi2.

    For testing you can use files passwd1 and passwd2.

  5. Write a script that computes the factorial of a given integer (n! = 1*2*...*n) so that it remembers and reports how many times the same argument has already been used. Allow for several simultaneous calls.

  6. Implement with sh scripts a daemon, that when started creates a pipe and remains in the background, and when the pipe is read, reports when it was last read before. When terminated it should remove the pipe. Startup/stop script should understand arguments start and stop.


File translated from TEX by TTH, version 1.98.
On 5 Feb 2001, 16:19.