Monday, December 19, 2011

Working with Directories

Files on UNIX are stored in directories. These are much like the directories on a PC or folders on a Mac. When you log on to your UNIX account, you are placed in your "home directory." Within your home directory you can have other directories, called "sub-directories." These sub-directories can also have other directories within them.

Directories make organizing your files easy. You can put all of your data files in one directory and all your programs in another, or, you can have a directory for each class you are taking. The term "path" is often used to refer to directories and their subdirectories.

pwd
The command pwd will tell you where you are witihin a directory structure.


cd [directory]


Use the cd command to change into the specified directory. The command cd without specifying any directories will bring you back to your home directory, and cd .. will bring you back up to the next highest directory. For example, the following command:
 cd  soc453
will make soc453 your current or working directory. If you give the ls command, you will see a list of files in that directory. Any new files you create will, by default, be created in that directory. If you issue the command:
     cd  ..
you will move up one level in the directory structure, to what is called the parent directory. In this example, the parent directory would be your home directory. You can return to your home directory at any time by issuing the cd command with no operands:
     cd


mkdir [directory]


The command mkdir will make (create) the specified directory. For example, issue the following command to make a directory named thesis within the current directory.
 mkdir  thesis
Or issue the following command to make a subdirectory named programs with the directory soc453:
 mkdir  soc453/programs


rmdir [directory]


The command rmdir will remove (erase) the specified directory. The directory must be empty of files or other subdirectories before it can be removed.

Printing

Before printing, you must determine which printer you want to use; not all printers are capable of printing from UNIX. Also, check the size of the file before you print it to avoid uneccesary use of paper and toner. To see a list of available printers, issue the command:

       printers  -L  |  more

This will give you a list of printers and their locations, as well as the alias by which you can refer to them. Once you have identified the printer you want to use, issue the lpr command

       lpr  -P  [printeralias] [filename]

where printeralias is the alias for a printer and filename is the name of the file you would like to print. For example:

       lpr  -P  nslaser test.do

will print a file named test.do, to nslaser, a printer in New South Building.


Quotas

Your UNIX account has a certain amount of space in which you can store files. The following command will show you how much space you are given ("quota") and how much you are currently using ("usage").

        quota -v

Running out of space is a common reason why you cannot create, copy or transfer new files into your account. Files created or modified when you are at or over your quota may be corrupted! There is a buffer space (the difference between your quota and your "limit"). However, this is small and only temporary. If you do not clear space that is over your quota, you will lose files. See below for solutions if you need more space.


Temporary Storage and Extra Space

Sometimes you may need extra space for just a short time, say to edit a very large file. You can access temporary storage in the /scratch directory. To do this, simply issue the command:

       mkdir  /scratch/[userid]

where userid is your userid. Be sure to use the slash (/) in front of scratch.

Now you can cd to this new directory and work with files in it just as you would in your own account. The system automatically erases files in the scratch directory 24 hours after they were last modified, so be careful not to leave anything important there.

If you find that you need more space on a permanent basis, then you can apply for a larger quota. Although there is a charge involved, academic departments will pay it for students who require the space for their research. See your department's undergraduate or graduate secretary. You can pick up the application at OIT (87 Prospect Ave) then get your department to authorize it.


Text Editors

There are several text editors available on UNIX. Among these are vi, emacs, and pico. Which one you use is a matter of personal preference. Try each and see what suits your needs best. Pico is similar to the editor used in the mail program, Pine, so if you already use Pine, Pico may be a good choice.


Help

You can get help on any command in UNIX by using the following command:

    man [command]

where command is the command with which you need help. For example, to get information on the copy command, cp, your would type:

    man cp

If you do not know the command you want you can type

    man -k [keyword]

where keyword is a topic rather than a specific command. You can also use the Internet to look up UNIX man pages.

No comments: