Lab 1 -- Learning UNIX

Name:

Instructions: Complete all parts of this exercise, checking off each part as you complete it. If a response is requested, type up the answer and when you are done, print the lab and submit it.

The following exercises are excerpts from several tutorials that appear in the text, "Just Enough UNIX." You can read the indicated chapters to learn more about each topic.

Note: Two useful time-savers in UNIX are the Tab key and the UP arrow. The Tab key will complete a filename, given some prefix of the filename. The UP arrow allows you to retrieve previous commands (also called history).

Shell Utilities at the command line (Chapter 3)

Log in to your account. Type in the following commands, and record the output:
  1. pwd
  2. who
  3. whoami
  4. date
  5. man cal

  6. (give a description of what you get.)

Files and Directories (Chapters 6-9)

  1. To ensure that you are in your home directory, type:
    cd
  2. Are there any user-defined files in your home directory?
    ls
  3. How many hidden files and directories do you have in your home directory?
    ls -a
    What do the hidden directories, . and .. refer to?

  4. To view permissions of files and directories, type: ls -l
    What permissions does the following code represent: drwxr--r--
    You can also combine options, such as typing: ls -la
  5. Create a file by redirection:
    cal 2010 > year2010
  6. What do you see when you type:
    more year2010
  7. cal 6 2010 > jun.2010; cal 7 2010 > jul.2010; cal 8 2010 > aug.2010
    Do ls to check whether you have indeed created the three desired files.
  8. cat jun.2010 jul.2010 aug.2010 > summer.2010
    What does the file summer.2010 contain?
  9. cp summer.2010 SUM.2010
    ls
  10. mkdir MyCalendars
  11. mv *2010 MyCalendars
    (This command will move all files ending in 2010 to the directory MyCalendars. You will get more practice with wildcards later in this lab assignment.)
  12. What happens from the following commands?
    cd MyCalendars
    pwd
    ls
  13. rm summer.2010
    ls
    What is the difference between the results from this ls command and the previous ls command?
  14. mkdir Summer
    ls
    rmdir Summer

    Chapter 10 (Pipes, Wildcard, Processes)

    What do the following commands do?
  15. who | sort
  16. cat SUM.2010 | less
  17. What do you see from the following command?

    ls *.2010
  18. To open a web browser, in the background, type:
    firefox &
  19. What do you see when you type: ps
  20. Attempt to close the browser, by typing:
    kill pid
    where pid stands for the process id number that you should have seen when typing ps.

    Chapter 11

    There is one new command in Chapter 11 that is very useful: grep searches text files for a pattern and prints every line in every file that contains the pattern. For example, if you wanted to search the source code of all of your C++ programs for a date in February, you would type: grep February *.cpp
  21. What do you see when you type: grep July *.2010

    Chapter 30 - Shell Scripts

  22. Open a text editor and type in the following. Then, save the file as myscript.exe:
    echo 'This is my very first script.'
    echo 'The current date is:'
    date
    echo 'My login is:'
    whoami
  23. Change the permissions on your file to allow executing the file.
    chmod u+x myscript.exe
  24. Run the script by typing: myscript.exe on the command line. What is the output of the script?

    One last step

    The command script saves all activity in a shell window to a file. Type:
  25. script log
  26. Do any sequence of three commands that you have learned in this lab. Which three commands did you choose?

  27. Type:
    exit
    cat log
    What do you see?
    You will find the script command very useful for supplying the output necessary for your programming assignments.