next up previous contents index
Next: Printing Up: Using the UNIX Platform Previous: Getting Help

Subsections


     
Working With Files

Your RCS files can store a variety of items -- programs, text files, image files, and homework assignments -- and you can create, edit, move, display, or remove these files as necessary. Like all RCS users, you have a ``home" directory, which contains your personal files, and which is always available for file storage. (However, if you use up all you disk space, you will have to delete files or rent more disk space.)

Each home directory has subdirectories, which you can simply think of as rooms in a warehouse, or folders in a filing cabinet.

Five subdirectories are already set up for you: public, public_html, private, bin, and yesterday. The public and private directories help you deal with file security and sharing. The yesterday directory contains copies of all your files as they were last backed up by the system. The public_html directory is used to store files that you want others to view through RPInfo (the World Wide Web). The bin directory is used to store executable files.         

You can find a summary of the file management commands in Appendix G, on page [*] of this document.

  
Securing Your Files

The Rensselaer Computing System uses the Andrew File System, or AFS, and this means that RCS' file permission scheme is a little different from those on UNIX systems that do not use AFS. Specifically, rather than setting access controls on individual files, AFS requires you to set your controls on the directory level. This means that files which require the same set of access controls should be placed in the same directory. Every directory has an     access control list, or ACL, and you can use these these ACLs to grant access rights to other users.    

Note that, even though other users can list the names of the files in your home directory, you are the only one who can actually read them and any files in subdirectories under it, except for those you specifically make ``public." Your public directory gives all users the ability to list names of files (lookup) and read and copy them; the private directory gives others no file permissions at all. Other users can't even list file names. So, the easiest way for you to give others read access to your files is to keep the files in your public directory, and the easiest way for you to keep files completely hidden is to keep them in your private directory.

For more information on file permissions, please read Memo RPI.114, Sharing Files on RCS UNIX Systems.            

  
File Backups: Using the yesterday Directory

If you accidentally delete a file, you can try to retrieve it from your yesterday subdirectory, which contains copies of all the files under your home directory as they existed at the time of the last system backup. (Backups currently take place on Sunday, Monday, Wednesday and Friday mornings between 3am and 6am.) If you need to retrieve a saved file, you can use the cp command to copy it out of the yesterday directory for use in your home directory, or another subdirectory you have created. (Please refer to the ``Managing Files" section of this document for more information on the cp command.)      

The yesterday directory is automatically set up under your home directory for your protection, and any files held in the yesterday directory do not count against your file quota. However, please note that the directory is read only, and you cannot delete it or the files in it.

       
Viewing Text Files (more and cat commands)

To view the contents of an ASCII text file, you can enter one of the following commands shown below, replacing filename with the name of the file you wish to view:

more filename or cat filename

If you enter the cat command, the text of the entire file will scroll by on the screen. In contrast, the more command displays one screenful of text at a time. If the message --More-- appears at the bottom of the screeni, press the SPACEBAR to continue to the next screen. Type q at anytime to quit viewing a file.

   
Managing Files (ls, cp, mv, and rm commands)

The commands presented in this section show you how to list files in a directory, copy, rename, and delete files, change between directories, and create and delete new directories.

Issue all of these commands from a UNIX prompt.

       
Listing Files (ls)

The ls command lists your files and subdirectories alphabetically. Enter the command:
ls
and the files and subdirectories in the current, or working, directory will be listed in columns. The table below includes several options you may use with the ls command to obtain different information about your files.
Enter This Command... To Do This...
ls -s List your files, including their respective file sizes
ls -l List your files, including their size, date of last change,
  and type (file, directory, etc)
ls -F List your files and directories. Directory names are followed by a
  slash (/) to distinguish them from files.
ls -R List the files in your current directory and the files of its
  related subdirectories

Filenames that begin with a dot designate hidden files; you don't need to work with these very often. For example, your .login_profile file contains settings that are applied every time you log in, and, while you might change this file once in a while, it isn't something you need to change often.

To list all of your files, including those that begin with a dot (.), such as .login_profile, enter

ls -a
 

HINT: UNIX uses an asterisk (*) as a wildcard character, which   you can use with many types of commands to affect a group of files that share common characters in their names. For example, you could list all the files that start with s by entering the following command:

ls s*

As another example, you could list all the files that end in .temp by entering:

ls *.temp

     
Copying Files (cp)

The cp (copy) command allows you to make a copy of a file under a new name. To use the command, enter the following command, replacing oldfile with the name of the original file, and replacing newfile with the name you want to give to the copy:

cp -i oldfile newfile

Please note that, while it is not necessary to include the -i option, it does tell the system to interact with you, and prompt you about your action before it happens. This gives you a chance to make sure you copy the file to the appropriate place. Otherwise, UNIX will overwrite any existing file without warning. That is, if you copy a file to a file that already exists, or if you use a new filename without realizing you already had a file with the same name, UNIX will do exactly what you told it to do, and copy one file right over another, deleting the information that already existed in the destination file. So, using -i gives you a chance to check on this before you give the go-ahead. However, if you prefer not to work in interactive mode, you can omit the -i option.

       
Renaming an Existing File (mv)

You can use the mv (move) command to change the name of an existing file. To do this, enter the following command, replacing oldname with the original filename, and replacing newname with the new name you want to give to the file:
mv -i oldname newname

If you use the -i option, the system interacts with you, and prompts you about an action before you perform it. As with the cp command, this is useful, as it gives you a chance to make sure you rename the file without overwriting an existing file without warning. That is, if you use the -i option when renaming a file, and specify a ``new" filename without realizing you already have an existing file with the same name, UNIX will copy one file right over another. So, the -i option gives you a chance to prevent this from happening.

However, as with the cp command, you can omit the -i option, if you prefer not to work in interactive mode.

         
Deleting a File (rm command)

The rm (remove) command enables you to delete a file so that it no longer exists. To remove a file, enter the following command, replacing filename with the name of the file you want to delete:

rm -i filename

As discussed above in the previous sections,the -i is optional.

NOTE: Be extremely careful if you use wildcards with the rm command, as you could accidentally remove more files than you intended. Remember: Once you delete a file, you cannot retrieve it!

Working with Directories (mkdir, rmdir commands)

     
Creating Directories (mkdir)

You will often find it useful to create (make) subdirectories for storing similar or related files. (Note that a subdirectory is simply one directory under another, and that we use the terms interchangeably.) For example, you can create a subdirectory, called Homework, under your home directory in which you can store your homework files. To create this subdirectory, you would enter the following command:
mkdir Homework

HINT: Starting your subdirectory names with a capital letter, and your files with lowercase letters, provides an easy way for you to distinguish directory names from filenames when you list the contents of your home directory (or another directory).

Note that some programs automatically create files and directories for you. For example, the first time you run FrameMaker, it will create a FrameMaker directory for you. You should use care if, for some reason, you decide to remove these directories.

Once you've created a directory (or subdirectory), it will appear in a file listing. For example, try using ls to list the contents of your current directory. If any directories exist, their names should appear in the listing. Next, try using the ls -l command, and notice that the directories are labeled with a d at the far left of the permission status codes, as shown below:


\begin{alltt}
drwx------ 2 doylel user 2048 May 15 17:00 test
drwx------ 2 doylel user 2048 Jun 29 08:45 work
\end{alltt}

Ordinary files are labeled with a hyphen (-). Other labels are also possible. See a UNIX reference for more complete information.

       
Changing Directories (cd command)

When you log in to UNIX, you begin your session in your home directory by default. However, you may find that you need to view a file in another directory; for example, a class assignment. To change to another directory, enter the following command, replacing directory with the name of the desired directory name:

cd directory

For example, if you were in your home directory and wanted to access files in a subdirectory called PhysicsClass, you'd enter the command:

cd PhysicsClass

HINT: To see the name of the directory in which you are currently working, enter the following command, which stands for ``print working directory."    

pwd

The full path of your current directory will be displayed.

Going Up? A directory may have many subdirectories, but each subdirectory has exactly one ``parent directory," or level above it; moving from a subdirectory to its parent directory is sometimes referred to as ``going up" a level. To do this, enter the following command, making sure to leave a space between the cd command and the ``..", which is a short way of referring to the parent directory:

cd ..

Going Home? To return to your home directory at any time, simply enter the following command:

cd

You can also use the tilde ($\sim$) as a shortcut to skip to any   subdirectory in your home directory from any place on the system. For example, let's say you're currently reading a file in /campus/doc/acs.memos, but you want to go to a file located in your PhysicsClass subdirectory (under your home directory). You could do this by entering the following command at the UNIX prompt. (Please note that there is no space between the tilde ($\sim$) and the slash (/)):

cd $\sim$/PhysicsClass

This command makes it easy to relocate to a subdirectory in your home directory, without needing to climb through a maze of directory levels, one level at a time. You can also use the tilde to change to someone else's home directory. For example, if your friend smithj had a file called notes in her public directory that she wanted to share with you, you could use the following command to display the file's contents:

more $\sim$smithj/public/notes


Using a Particular File:   From time to time, you might need to tell UNIX to specifically use a file in the directory in which you are currently working, instead of running a command that may have the same name. For example, let's say that you have a file named test in your current directory. However, test is also the name of a UNIX command. Therefore, if you want UNIX to use the test file, instead of running the test command, you would enter the following command:

./test


Deleting Directories (rmdir command)

To delete (remove) a directory, change to its parent directory and enter the following command, replacing directory with the name of the directory you wish to delete:      
rmdir directory

Note that before you remove a directory, you must first empty it by deleting all the files in it, or moving them out of the directory. (You can save a file in another directory by moving it with the mv command; all you need to do is specify the full directory path in which you want to save the file. For example, to move a file called lab12 from your public directory to a subdirectory in your home directory called Chem/hw, you would enter the following command:

mv lab12 $\sim$/Chem/hw/lab12

To remove a directory and all its subdirectories, use the command

rm -r directory

Be careful to specify exactly which directory you want to remove! For example, suppose you are in a directory with two subdirectories under iti: one called HW (for homework) and the other called CW (for classwork). Now, let's say you want to remove the subdirectory called CW, but it contains a file that you want to save, called labs. You could first use the following command to move labs to your HW subdirectory:

mv CW/labs HW/labs

You could then use the following command to safely delete the CW subdirectory and all its files:

rm -r CW

   
Piping Information

In UNIX, you can ``pipe'' information from one command to another, literally redirecting the output of one command so that it becomes the input of another command. Why might you want to do this? Well, as an example, let's suppose that you want to view a long directory listing, with user permissions for each file, on your screen. However, if you use the ls command by itself, the text scrolls by too quickly on the screen. You can avoid this by piping the ls output to the more command, thereby making the output stop at each screenful and placing the

\begin{alltt}
---More---
\end{alltt}
message at the bottom of the screen. You can then press the SPACEBAR to continue viewing the file screen by screen.

Symbolized by a vertical bar |, a pipe redirects output from one command to act as input for another. A typical pipe command has a format like this, replacing outfrom with the command you are redirecting, and replacing into with the command to which you are redirecting the output from the first command:

outfrom |into

For example, to use the ls -la command to see a list of files, including the filenames beginning with a dot, and their permission status, and then redirect the output from that command into the more command, you would enter the following:

ls -la | more
You can also direct the output of a command into a file by using a chevron (>) instead of the pipe symbol(|). For example, suppose you just read a system bulletin that you would like to save in a file. You could issue the following command to do this:
msgs 196 > bulletin.txt

This would take the text in system bulletin 196 and save it in a file called bulletin.txt.


next up previous contents index
Next: Printing Up: Using the UNIX Platform Previous: Getting Help
Send comments to consult@rpi.edu.