Sei sulla pagina 1di 9

Introduction to UNIX

UNIX is the name of the operating system used on the Economics Sun Network. To learn how to access your account and change your password, refer to the handout titled Getting to Know the Economics Dept. Computers.

I. Files and Directories


A computer file is a place for storing data, programs and text. Groups of files are stored in directories. Directories can also contain subdirectories.

Naming Files and Directories


UNIX file and directory names cannot have intervening spaces. So a file or directory name like HW One is not permitted. However, you can use a symbol such as . or _ or - to increase the readability of your file or directory names. HWOne, HW.One, HW-One, or HW_One are all permitted. UNIX is case sensitive, so it will distinguish between uppercase and lowercase letters. UNIX names are usually limited to fourteen alphanumeric characters. Among the symbols you should avoid using in file or directory names are * ? / " ' ` [ ]

Hierarchical File Structure


The file structure in UNIX is hierarchical, which means that a directory can hold several other directories, known as subdirectories, and subdirectories can hold more subdirectories, and so on. UNIX uses the symbol / between the directory name and the filename as well as between directory names. For example: /home/grad/mtasci/hwone.tsp is the path name for a file called hwone.tsp, which is in the directory kjordan, which is in the directory grad, which is in the directory home. This means that the directory path to the file hwone.tsp is /home/grad/mtasci. Only directories can hold other directories and files. Files can hold data, programs and text, but they cannot hold directories or other files.

Home Directory
Every user is assigned a home directory. When you first log in, you are placed in this home directory. Home is your starting point in your file hierarchy. Your home directory will be: /home/grad/userid or /home/ugrad/userid or /home/class/userid.

Print Working Directory (pwd)


The directory you happen to be in at any point is called your current or working directory. To find out what your working directory is, type pwd and then press <return>at the prompt. The response the computer gives to this command is your current place in the file hierarchy.

List the Files and Directories within a Directory (ls).


To list the files and directories within your working directory type ls and then press <return>at the prompt. To get more info about the files and subdirectories in your directory, like permissions or date last used, type ls l.

Create a Directory (mkdir newdirectoryname)


To create a directory, type mkdir newdirectoryname at the prompt and then press <return> . For example: mkdir project will create a directory called project. You can now use the ls command to see if the directory was indeed created. The directory project should now appear when you type the ls command, along with any other files or directories contained within this working directory.

Move to a Directory (cd directoryname)


To move into a directory type cd directoryname and then press <return>at the prompt. For example:

cd project will change your current directory to the directory called project. You can use the ls command to see what files and directories are within this directory. (If the directory is empty, the ls command will simply return another prompt.) A very useful UNIX command cd .. will take you to the parent of the current directory. For example, if we are in the /home/grad/mtasci/project directory, the command cd .. will take us to the /home/grad/mtasci directory. Another useful UNIX command. cd will take you directly to your home directory.

To Copy a File (cp filename newfilename)


To make a copy of a file, type cp filename newfilename at the prompt and press <return>. First, let's create a file we can copy. To make an empty file called homework1, type: touch homework1 To make a copy of the file called homework1 and call it homework2, type: cp homework1 homework2 You can use the ls command to check if you have two new files called homework1 and homework2. To copy a file that is stored somewhere other than your own account, you will need to know the full path of the file you plan to copy. The command is cp location/filename newfilename. For example, to copy the file program.tsp from the /summit/practice directory type: cp /summit/practice/program.tsp program.tsp This program is now sitting in your current directory. You can use the ls command to check if you now have a file called program.tsp.

To Copy a Directory (cp -r directoryname newdirectoryname)


To make a copy of a directory, type cp -r directoryname newdirectoryname at the prompt and press <return>. For example, to make a copy of the directory called project and call it project2, type: cp -r project project2 You can use the ls command to check if you have a new directory called project2.

To Remove a File (rm filename)


To delete a file type: rm filename. For example, rm homework1 will delete the file called homework1. You can use the ls command to see that this file no longer exists.

Remove a Directory (rmdir directoryname or rm -ir directoryname)


To remove an empty directory type rmdir directoryname and then press <return>at the prompt. For example: rmdir project will remove the directory called project. You can use the ls command to determine whether the directory has been removed. If the directory project had contained any files or directories, UNIX would warn you and refuse to delete the directory. To remove a directory with files in it, type: rm -ir directoryname. The computer will give you the following message when you try to remove the directory called project if this directory contains files: rm: examine files in directory project (y/n)?

If you wish to examine the files, type y and press <return>. Otherwise, type n and press <return>

Moving a File or Directory (mv filename newdirectory/newfilename)


To move a file or directory into another directory, use the following commands: mv filename newdirectory/newfilename mv directory newdirectory When you are specifying newdirectory be sure to include the full path. For example, if we want to move the file program.tsp from our home directory into a subdirectory we have created called project2, we use the following command: mv practice.tsp project2 Notice that we didn't specify the newfilename. If you don't plan to change the name of the file you are moving, you don't need to include newfilename in your command. Note: You can also use the Nautilus File Manager to create and manipulate files and directories. To start the Nautilus File Manager use your mouse to click on the Applications button on the Session Control Panel (top left corner of screen) and then click on Nautilus File Manager.

II. Display a File One Page at a Time (more filename)


To look at a file one page at a time, use the following command: more filename Suppose you want to look at the sasprac.data file that is under /summit/practice directory. There are two ways we could look at this data. cd /summit/practice <return> more sasprac.data <return> (use the space key to move through the pages) or more /summit/practice/sasprac.data <return> (use the space key to move through the pages) If we use the first method, we must remember to move back to our home directory when we are done. We can use the quick command we learned above, i.e. type:

cd <return> If we use the second method, we never leave our home directory.

III. Logging in to a Different Server


When you log in to a X-term in the fourth floor Sun Lab, you are automatically logged in to one of the servers such as rochelle. The name of the server you are logged in to is included in your prompt. Other servers are available for you to use. To change your server type: rlogin newserver <return> Suppose you were initially logged into server Rochelle, then you can type mercury as the newserver to connect to server mercury.

IV. Checking Your Disk Quota (quota -v)


You have each been given an account with 500 megabytes of diskspace. You will want to keep an eye on your use of this space, simply because it is not unlimited. To see how much of your disk quota you are using, type the command: quota -v You should get a response that looks something like the following:
Disk quotas for mtasci (uid 8534): Filesystem /home/grad usage quota limit timeleft files 1371 quota -1 limit -1 timeleft

333564 512000 512000

The second column of the computer's response tells you how much space you are using in kilobytes. The third column tells you your quota in kilobytes. So user mtasci is now using 333564 kilobytes of his quota of 512000 kilobytes. If you are running out of disk space, you may try compressing your files using the compress utility, removing files you no longer need, or moving files to a CD. If you need to store large data sets and files, please store them under share directory. It is located under /share/grad We recommend that you create your own directory and store your files in that directory so that share directory remains neat and practical.

V. Printing
Printing a File (lpr -P)
To print a text or postscript file, type: lpr -Pprintername filename The printernames for the two printers available in the Sun Lab are lw4 and lw5. For example, to print the file called psone.tex on lw5, type lpr -Plw5 psone.tex If you are using a program like MS Word, you will have to print your document from within the program. You can't print the MS Word document from the prompt with the lpr command.

*Important*
Once you have sent a print job to the printer it enters a queue (a line of print jobs). This is true for all print jobs, including those from programs like MS Word. If your print job doesn't come out of the printer right away, don't just send the command again, try to determine what has happened. The first step is to check the print queue.

Checking the Print Queue (lpq)


To check the print queue, type: lpq -Pprintername.

For example, to check the queue for printer lw5, type: lpq -Plw5. and the computer will give you the following information: Column One: The rank of each print job (i.e. where in line the print job is). Column Two: The name of the user who sent the print job (the owner). Column Three: The number assigned to each print job. Column Four: The name of the file to be printed for each print job. Column Five: The size of the file.

Killing a Print Job (lprm)


First check the print queue to determine the job number of the print job you have sent.

The job number is in the third column of output resulting from the command to check the print queue (lpq). To kill the print job type: lprm -Pprintername jobnumber For example, to kill print job 13670 after it has been sent to the printer lw5, type lprm -Plw5 13670 If the print job is already coming out of the printer the lprm command will no longer kill the print job. However, you can press the <RESET> button on the front of the printer to kill the print job as it is coming out of the printer.

VI. To Get More Information on Specific UNIX Commands (man unixcommand)


The man program gives you online information on the syntax and options of specific UNIX commands. To use the man program you need to know the command you want more information about. To use the man program, type: man unixcommand For example, to get information on the ls command, type: man ls If the information is longer than a page, press the space bar to continue to the next page. If you do not want to see the whole document, you can quit by typing q and then <return>. To print the contents of a man page, type: man pagename | lpr -Pprintername where pagename is the name of the command you want information on. For example, to print the contents of the man page on the UNIX command ls, type man ls | lpr -Plw4

VII. Logging Out

To finish your session, type exit and then press <return> at the prompt or click on Logout on the Actions tab (in top left of screen). It is important to always exit when you are done working on the system to protect the privacy and integrity of your account.

Potrebbero piacerti anche