Introduction To UNIX: I. Files and Directories
Introduction To UNIX: I. Files and Directories
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”.
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 * ? / " ' ` [ ]
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.
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.
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.
To create a directory, type mkdir newdirectoryname at the prompt and then press
<return> .
For example:
mkdir 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.
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.)
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.
cd
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)
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.
For example,
rm homework1
You can use the ls command to see that this file no longer exists.
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:
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.
more filename
cd /summit/practice <return>
more sasprac.data <return>
(use the space key to move through the pages)
or
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>
Other servers are available for you to use. To change your server type:
Suppose you were initially logged into server Rochelle, then you can type mercury as
the newserver to connect to server mercury.
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):
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:
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
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.
lpq -Pprintername.
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.
For example, to kill print job 13670 after it has been sent to the printer lw5, type
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.
man unixcommand
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>.
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
It is important to always exit when you are done working on the system to protect the
privacy and integrity of your account.