Homework 2

Due Wednesday September 13


  1. Print the date in universal time.
  2. Show the complete path for "python".
  3. Find the "rev" command. What does it do? (Hint: you'll need this later.)
  4. Which directories are in your PATH variable? i.e. what is the value of the PATH variable?
  5. You want to add the directory "/usr/sbin" to your PATH. Show how you would do this.
  6. How much disk space is being used in your home directory?
  7. How much space is free on the filesystem where your home directory resides?
  8. How many filesystems are there on the system?
  9. Show a list of all processes you are currently running. Now show a list of all processes that everyone is running.
  10. You have started a process and it has run amok. Assume the process in question is called "myprocess". Show how you would remove the process.
  11. Who is currently logged in?
  12. Show all of the environment variables you currently have set.
  13. The command "echo" echoes its argument to standard output. For example:
    echo foo
    
    Show how you would redirect the output to standard error.
  14. Show how you would list all files in a directory that: Note that if you "ls" a directory it will by default list the contents of that directory. To list the directory's name only do "ls -d"
  15. You type:
    echo foo bar #baz
    
    What do you expect to happen? What does happen? Why?
  16. /home/rws/data/alice.dict contains a list of all words that occur in Alice in Wonderland. The following script pastes two files together, line by line, and then selects those lines where the corresponding lines in the two files are identical:
    
    paste file1 file2 | awk '$1==$2'
    
    
    Use this to find the list of all palindromes used in Alice.
  17. One useful command is "basename": this takes a filename and returns the filename without a given suffix. Thus
    basename foo.c .c
    
    will strip the ".c" and return "foo".

    Another useful facility in bash is the backquote evaluation. If I type:

    ls `echo foo.bar | rev`
    
    (note: those are backquotes not forward quotes) bash will first evaluate what's within the backquote (in this case returning rab.oof) and then pass it as an argument to the function ls.

    Use these two facilities to write a command pipeline that strips a given prefix off a given filename.