A little UNIX and Pico

File Names

For every file you create, you must supply a name. In Unix, the following characters have special meaning, so you should avoid using them in file names:

    /    \   "    `    '    *    |    !    ?    ~    $    <    >    &

File names may be between 1 and 255 characters long, but you will find that short, descriptive names are easiest to use. File names should not contain spaces. Instead of spaces, use underscores or periods to separate names made of multiple words, as follows:

    mail.Jan     annual_report     unix_tips

Also, Unix distinguishes between uppercase and lowercase letters. For example, Unix would treat these as three different files:

    project1     Project1     PROJECT1

Create a File With a Text Editor

Pico is a text editor that permits you enter, edit, and re-arrange text in files.
  • Pico is easier to learn and use.
  • Pico contains online help text and lists the most commonly used commands at the bottom of each screen.
  • Pico is designed for worry-free exploration.

To create a new file using the Pico text editor, enter:

    pico   file

Note: the p in the pico command is lowercase.

This starts the Pico text editor and opens a blank file. Pico assigns to that file the name you specify. Use your keyboard to add text to the file.

To save a file and exit the Pico text editor:

  1. Press <Control>x
    This means hold down the Control key, while you press the x key.
  2. In response to the question:
    Save before leaving (y/n)?
    Type y
  3. In response to the prompt:
    Filename to write:
    Press <Return> or enter a new name.

To re-open and edit a file with the Pico text editor, enter:

    pico  file

Where file is the name of the file you want to edit.

To create a file named sport.quote, enter:

    pico sport.quote

This starts the Pico text editor with the file sport.quote. Add to this file the following lines of text:

It ain't over till it's over.
We're taking this season one game at a time.
Football players make football plays.
Turn out the lights, the party's over.

When you finish typing, save and exit sport.quote using the three steps that precede this example.

To re-open and edit sport.quote, enter:

    pico sport.quote

List Your Files

To list the files in your current directory, use the ls (list) command. At the system prompt (e.g., dante%), enter:

    ls

Your list might resemble the following:

    mail    murphy.law    phone.dir    sport.quote

To Move to Another Directory

cd    myChildDirectory

cd    ..

moves to the immediate parent directory

Copy a File

To copy a file, use the cp (copy) command. Enter:

    cp  file1   file2

This creates a copy of file1 and names it file2.

To copy a file to a different directory, enter:

    cp  file  directory

This creates a copy of the file you specify in directory the you specify.

Change the Name of a File

To change the name of a file, use the mv (move) command. Enter:

    mv  file1   file2

This changes the name of file1 to file2.

View a File

To view a file, use the more command. Enter:

    more  file

This starts the more program, which lets you view the file you specify one screen at a time. Use <Spacebar> to scroll forward one screen, <Return> to scroll forward one line, and q to quit the more program. To search for a word in the file, type / followed by the word and then press <Return>.

Delete a File

To delete a file, use the rm (remove) command. Enter:

    rm  file

This permanently removes the file you specify.

Make a Directory

To make a directory, use the mkdir (make directory) command. Enter:

    mkdir  directory

This will make a directory with the name you specify

To make a directory for your chemistry papers and assignments, enter:

    mkdir Chemistry

This makes the directory named Chemistry. If you begin your directory names with a capital letter, they are easier to distinguish from your file names.

Delete a Directory

You can use the rmdir (remove directory) command to delete a directory. Before you can delete a directory, it must be empty of all files.

To delete a directory, enter:

    rmdir  directory

Determine Your Current Directory

If you forget the name of your current directory, you can use the pwd (print working directory) command.

To display the name of your current directory, enter:

    pwd

For a user with the userid "jjaudubon," who is working in their home directory, the pwd command display would look something like this:

    /ua19/S0/jjaudubon

File and Directory Permissions and Access

You decide who can use your files and directories by setting permissions. Each file and directory has three types of permissions:

  1. Read (r) gives permission to view, print, and copy.
  2. Write (w) gives permission to edit, delete, and save.
  3. Execute (x) gives permission to run an executable file, such as a program. In the case of a directory, (x) allows you to change to that directory.

You set these permissions for three classes of users:

  1. You, the owner of the file.
  2. Your group.
  3. All others.

You can view the permissions of your files using the ls -l command. The ls -l command lists the contents of your directory in long format. For example:

  drwxr-xr-x 2 userid   512 Sep 14 08:24 Sales
  drwxr-xr-x 2 userid   512 Sep 14 08:24 Receipts
  -rw-r--r-- 1 userid   0 Sep 14 08:24 budget

The first character indicates file type: a - (hyphen) indicates an ordinary file, and a d indicates a directory. Unix considers the next nine characters as three sets of three. The first set of three determines the owner's permissions, the second set determines the group's permissions, and the third set determines all others' permissions.

If you wish to change the permissions of a file or directory, you can use the chmod (change mode) command. The chmod command uses a number code. Each permission setting corresponds to a number between 0 and 7. For each file or directory, you assign three numbers between 0 and 7.

  • The first number gives the permissions for the owner.
  • The second number gives the permissions for the owner's group.
    Note: On Uniform Access accounts the group permission has no meaning because all users belong to the same group and no other groups can be formed.
  • The third number gives the permissions for all others.

The following shows how the permissions correspond to each number code:

  7   Read, Write, and Execute   (rwx)
  6   Read and Write only   (rw-)
  5   Read and Execute only   (r-x)
  4   Read only   (r--)
  3   Write and Execute only   (-wx)
  2   Write only   (-w-)
  1   Execute only   (--x)
  0   No Permissions   (---)

To change the permissions of a file, enter:

    chmod  code  file

Where code is the three-digit number corresponding to the permissions you desire.

Note: When you set permissions for a file that you want others to use, you must make sure that your directories along the pathname leading to the file also have the appropriate permissions.

To set the permissions of a file so other users cannot read or write to it, enter:

    chmod 600  file

To see the new permissions for the file you specify, use the ls -l file commmand.
The permissions should now be -rw------