ERODD HOME

Operating Systems CPSC 304
Earl Rodd erodd@malone.edu Extension 8546 www.malone.edu/erodd
Linux Command Shell Lab

We will use LINUX on the TS111 lab systems. The purpose of this lab is to become familiar with the basics of the UNIX shell.

The basics of how to access LINUX are described here.

  1. Check your current directory with the pwd command.

  2. Check to see what is in your current directory with the "ls -l" command.

  3. In order to be sure there are some files, do this:
  4. See what is in your directory with "ls" and then "ls -l" and then "ls -ld" and then "ls -la".
    What can you see about the length of filenames?

  5. Do a
    df
    command. This shows the currently mounted filesystems. Which filesystem has all the space? Is your current directory on this filesystem?

  6. Use the "cat" command to display the file /etc/inittab
    This file is the list of things started with UNIX is booted.

  7. Use "cat" to list a file which does not exist.
    Now redirect output from cat with "cat xxxx > soiii" (iii is your initials so you don't conflict with other students). Use "ls -l" to see how large "soiii" is.
    Do you still see the error? Now redirect standard error with:
    cat xxxx 2> seiii
    What do you see? How large is "seiii"? What is in "seiii"?

  8. Now create a file using "echo". First try
    echo my data
    to see that echo simply writes to standard out. Use redirection of standard out
    echo my data > fiii
    to create a file named fiii. Now use the "ls" command to make sure you created the file. Now erase this file with
    rm fiii

  9. Use "cat" to see what is in the files "ss1" and "ss2". Now sort one of these files with: "sort < ss1".
    Now use "cat" to display them both at one time.

  10. Now we can pipe the output of cat into sort to sort both files together!

  11. Try grep: For example, try:
    grep A ss*
    This will show all lines in files starting with "ss" which have the string "A" in them.

  12. grep is a very powerfull command! We are using only its most basic function! Two simple options are:
    grep -r string *  # Search all files in the current directory, and
                      # all its subdirectories (-4) for "string"
    
    grep -l string *  # Search all files in the current directory for "string",
                      # but display just the filenames, not the lines
                      # containing the string.
    
    grep "This Day" * # Notice the quotes. If a search string has blanks, or
                      # other special characters, it must be enclosed in ""
    

  13. Another important shell command not in the book is "find" which is like DOS dir with the "/s" option. "find" has other advanced options such as executing a command using each file found as an argument.

  14. We will use a command not in the book: find. It was designed when the ls command did not have an option to recurse subdirectories. Still, find has useful function like finding files with a modification date less (or more) than so many days old. Also, find can execute a command against each file found. Try the command:
    find /usr/local -name "sw*" 
    which will display all files in the /usr/local directory and its subdirectories which start with the letter "sw".
  15. To search the entire system for a file, the command is:
     
    find / -name "somefile"
    
    Two warnings:
    1. Do not use a find of the whole system while logged on with mnet. This will search the whole tdrive which takes a long time!
    2. Many directories deny permissions to your userid and will produce a LOT of error messages. To avoid them, redirect error output to the special device /dev/null: find / -name "somefile" 2> /dev/null
  16. Try using sort with STDIN input (i.e. the keyboard). Just type "sort" with no parameters. You can then type lines to be sorted. Terminate the input with Ctrl-d and sort will write a sorted list to standard out (the screen).

  17. Try using sort using redirection. Create a file using "vi" and then sort it. For example, to sort file "/tmp/abc",
    sort < /tmp/abc
    
    will put the sorted output to the console (STDOUT). To put the sorted output to a file, redirect the output. For example:
    sort < /tmp/abc > /tmp/sortedfile
    
  18. Do a command with lots of output. You can try
    ls -l /usr/bin
    
    Now use the more command:
    ls -l /usr/bin | more
    
    LINUX has a more powerful processor called less
    ls -l /usr/bin | less
    
    The less command accepts normal vi editor commands including PgUp and PgDn keys and the search command (/string). To quit, type :q and press ENTER.

  19. Examine all the "environment" variables available to your userid:
    env
    
  20. Use echo to display an environment variable. We will display $PATH.
    echo $PATH
    
    Note: In Windows, display an environment variable with:
    echo %PATH%
    
  21. Create your own environment variable. Pick your own name __________
    Set the variable.
    your-name=value
    
    Note that there CANNOT be blanks around the '=' sign!!

    Now display your variable:

    echo $your-name
    

    Remember, that names are case sensitive!
    In a later lab, we will see that programs can access these environment variables.

To Turn in

Nothing. There is no grade on this lab. You will, however, be responsible to understand this lab on quizzes and exams.