NEW BRUNSWICK COMPUTING SERVICES
USER SERVICES GROUP

The Basics Of The UNIX Operating System
Exercise Answers

Practice 1 - Basic Use of Metacharacters

In this practice you will practice using wild cards and a few other metacharacters.

  1. List the files in the directory "/bin" that end in "sh". What command did you use?
    ls /bin/*sh

  2. On one line, use the "cd" command to first go to your home directory then to the "UNXclass" subdirectory. What is the command line?
    cd ; cd UNXclass

  3. What command lists the files in the current directory that begin with upper case letters?
    ls -d [A-Z]*

  4. If they do not already exist, create three new directories in the UNXclass directory; "Letters", "Programs", and "Misc". What command(s) did you use?
    mkdir Letters Programs Misc

  5. Copy all files in the current directory whose names contain the character string "let" into the subdirectory "Letters". What command did you use?
    cp *let* Letters

  6. Copy all files in the current directory whose names end in ".c" or ".h" into the subdirectory "Programs". What command did you use?
    cp *.[ch] Programs

  7. Copy all files in the current directory whose names contain the character strings "notes" or "misc" into the subdirectory "Misc". What commands did you use?
    cp *notes* Misc
    cp *misc* Misc
    or
    cp *notes* *misc* Misc

  8. Copy all files which begin with "copy.me" into the "UStoreIt" subdirectory. Move all files which begin with "move.me" into the "UStoreIt" subdirectory. What commands did you use?
    cp copy.me* UStoreIt
    mv move.me* UStoreIt


  9. Delete all files which contain the sequence "del". What command did you use?
    rm -i *del*

End of Practice 1 - Basic Use of Metacharacters


Practice 2 - Basic Emacs Use and Command Line Editing

This practice will familiarize you with how to start Emacs, exit Emacs, start the Emacs tutorial and basic use of command line editing.

  1. Use emacs to edit the file "big.file" in the UNXclass directory. What command will do this?
    emacs big.file

  2. What do you type to exit emacs?
    <CTRL>x <CTRL>c

  3. Start the emacs tutorial and read the first couple screens worth of instructions. Which command did you use? Be sure to exit emacs afterward.
    teach-emacs or start emacs and type <CTRL>h t

  4. Using command line editing go back to the command entered in #1 above. Change the "b" in "big.file" to "B" and hit return. What occurred? Exit emacs.
    <CTRL>p 2 times then <CTRL>b 8 times, <CTRL>d, "B" opened an empty file.

  5. Using command line editing go back to the command entered in #1 above. Move the cursor to the space after "emacs". Using a single control keystroke (<CTRL><key>) delete "emacs". Replace it with "ls -l" and hit return. What happened?
    Use <CTRL>w
    Got a long listing of "big.file"

End of Practice 2 - Basic Emacs Use and Command Line Editing


Practice 3 - Working with File Permissions

This practice will familiarize you with how UNIX permissions work. This practice will also generate error messages to familiarize you with what file permission error messages look like.

  1. View the file "README.1", using the command "cat". What message did you get?
    This is a simple bit of text

  2. View the file "README.2", using the command "cat". What message did you get?
    README.2: Permission denied
    cat cannot read it because you do not have read permission on that file.

  3. cd into the NoWrite directory. Create a new file, named try.me, using the command
    touch try.me
    What happened and why?
    You cannot create try.me because you do not have write permission in the NoWrite directory.

  4. Use cd to go back up one level to UNXclass. What is one command that will change the permissions on the NoWrite directory to allow the creating of files.
    chmod u+w NoWrite or chmod 700 NoWrite

  5. Run the command runMe.1 by typing ./runMe.1 . What did it print out? What are its permissions?
    You ran runMe.1
    permissions are rwxr-xr-x (755)

  6. Run the command runMe.2 by typing ./runMe.2 . What did it print out? What are its permissions?
    The file does not run because you do not have execute permission on it. Permissions are rw-r--r-- (644)

  7. Permission practice- change the following files, which currently have no permission settings, to have the specified permissions (use chmod with either symbolic or numeric permission specs and use ls to check your success):
    File Permissions Symbolic Mode Command Numeric Mode Command
    pp1 rwxrwxrwx chmod a+rwx pp1 chmod 777 pp1
    pp2 rwxrwxr-x chmod ugo=rwx,o-w pp2 chmod 775 pp2
    pp3 rwxr-xr-x chmod u+rwx,go=rx pp3 chmod 755 pp3
    pp4 r-x------ chmod u=rx pp4 chmod 500 pp4
    pp5 r--r----- chmod ug=r pp5 chmod 440 pp5
    pp6 rw-r--r-- chmod u=rw,go=r pp6 chmod 644 pp6
    pp7 r--r--r-- chmod ugo=r pp7 chmod 444 pp7
    pp8 rw-rw-rw- chmod ugo=rw pp8 chmod 666 pp8
    pp9 rwx------ chmod u+rwx pp9 chmod 700 pp9


  8. Set up the foundation for a web page - NOTE If you have already created a web page actually do only steps A, E and H to verify the settings, write down the answers for the other steps
    Action Command Needed
    A. Change to your home directory cd
    B. Make a directory named public_html mkdir public_html
    C. Allow group and others to be able to read and execute on your home directory chmod a+rx .
    D. Allow group and others to be able to read and execute on the public_html directory chmod a+rx public_html
    E. Verify the permissions on your home directory and on public_html ls -ld . public_html
    F. Use touch to create an empty file named index.html in the public_html directory touch public_html/index.html
    G. Allow group and others to be able to read all files in the public_html directory chmod a+r public_html/*
    H. Verify the permissions on the file(s) in public_html (your home page files) ls -l public_html/*

    The previous will set up the basic directories, files, and permissions needed for a web page. The actual development of a web page is another project altogether.

  9. Optional: Restore the original startup settings to your account.
    On rci:
    mv .login .login.class ; mv .login.OLD .login
    mv .cshrc .cshrc.class ; mv .cshrc.OLD .cshrc


    On eden:
    mv .login.local .login.local.class
    mv .login.local.OLD .login.local
    mv .cshrc .cshrc.class ; mv .cshrc.OLD .cshrc

End of Practice 3 - Working with File Permissions

Answers to practice exercises

7/26/04

Rutgers University Computing Services

UNX 1 ES