Objectives:: Introduction To Unix
Objectives:: Introduction To Unix
Objectives:: Introduction To Unix
Objectives:
This Lab is for new users of the UNIX timesharing system. The students assumed to have some
prior experience with computers, but not necessarily with UNIX. The followings are the primary
objectives of this lab session:
What is Unix
Understanding Unix File System
Login to Unix Machine via Telnet
Create and maintain files and directories of files.
Be familiar with PICO to create and modify a text file
What is Unix
UNIX is a powerful operating system originally developed at AT&T Bell Labs. It is very
popular among the scientific, engineering, and academic communities due to its multi-user and
multi-tasking environment, flexibility and portability, electronic mail and networking
capabilities, and the numerous programming, text processing and scientific utilities available.
The UNIX system is mainly composed of three different parts: the kernel, the file system, and
the shell.
1. The kernel is that part of the system which manages the resources of whatever computer
system it lives on, to keep track of the disks, tapes, printers, terminals, communication
lines and any other devices.
2. The file system is the organising structure for data. The file system is perhaps the most
important part of the UNIX operating system. The file system goes beyond being a
simple repository for data, and provides the means of organizing the layout of the data
storage in complex ways.
3. The shell is the command interpreter. Although the shell is just a utility program, and is
not properly a part of the system, it is the part that the user sees. The shell listens to your
terminal and translates your requests into actions on the part of the kernel and the many
utility programs
local src
In Unix, everything is treated as a file. A directory is a file. It is a file that contains a list of files
and information belonging to those files. This would include things like who “owns” (created)
the file, how long it is, and who can use it. Since a directory is simply a list of files, it can
contain any file in it, including other directories.
However, a relative path name specifies the path relative to your current working directory.
Relative path name are more convenient because they are shorter, but must be used with care.
They never begin with / (slash). Now, we have to introduce two special directory entries:
. the current directory
.. the parent directory
Examples: User the above diagram and assume that your current working directory (your
current position in the file system) is ugics:
Important notes:
As the number of machines connected to the network increases, the probability of having
your network transactions “sniffed” (that means viewed by unauthorized programs or
users) increases. Therefore, the most suitable way to connect to Unix system is through
secure shell (SSH) program. The program SSH is an access method similar to telnet.
The primary difference is that the entire data stream put on the network by SSH is
encrypted. For running SSH session on any Unix machine, you need to have SSH client
on your PC. The most popular SSH client is PuTTY. You can get and setup PuTTY from
this link.
*
The link is http://www.ccse.kfupm.edu.sa/~waqqas/tmp/pages/services/ccse_accounts/list_of_unix_machines.php
Unix Commands:
1. Listing files and directories
ls (list)
When you first login to any Unix machine, your current working directory is your HOME
directory. Your home directory has the same name as your username.
There may be no files visible in your home directory, in which case, the UNIX prompt will be
returned. Alternatively, there may already be some files inserted by the System Administrator
when your account was created.
ls does not, in fact, cause all the files in your home directory to be listed, but only
those ones whose name does not begin with a dot (.). Files beginning with a dot (.)
are known as hidden files and usually contain important program configuration
information. They are hidden because you should not change them unless you are
very familiar with UNIX!!!
Example 2: To list all files in your home directory including those whose names begin with a
dot, type:
% ls -a
The / character is the directory name for the root directory. What you should see are the
subdirectories and any files that are located in the root directory.
Exercises (1a):
1. Try putting the l option. What is the output?
2. Try putting the a option and the l option together (-al). Does the order of the
parameters affect the output?
3. Write a command to display all files in the directory /etc ?
2. Making Directories
mkdir (make directory)
We will now make a subdirectory in your home directory to hold the files you will be creating
and using in this course.
Example: To make a subdirectory called ics431 in your current working directory type
% mkdir ics431
Now to see the directory you have just created, type
% ls
Please note that creating a subdirectory will not change your current position in the file
system tree. Thus, after creating ics431, your current directory stills remain you HOME
directory.
Exercises (1b):
1. Make another directory inside the ics431 directory called “LabOS” then make
“LabOS” your current working directory.
2. Now type the command:
% cd ..
followed by:
% ls
In which directory you are located now?
3. Type the following command
% cd /etc/fs
followed by:
% ls
In which directory you are located now?
4. Now enter the command:
% cd
In which directory you are located now?
5. Write a single Unix command to make “LabOS” your current working directory.
4. Pathnames
pwd (print working directory)
The pwd command is very useful to know your current position in the file system. It displays the
full path name of your current working directory.
Example: Now, type
% pwd
What is your current working directory?
3. To exit Pico, press [Ctrl]+[x]. Since you have mode some changes, Pico asks
whether to same them. Type y (yes) or n (no). If you type y, Pico displays the
filename. (To save the edited file under a different name, delete the filename and
type a new one.) Press [Return].
Exercise (1c):
Modify the above file such that the content will be as follow:
Hello world,
My name is Ahmed Abdullah
I’m a student in KFUPM. I’m learning Unix OS
So this is my first lab
cat (concatenate)
The command cat can be used to display the contents of a file on the screen.
Example: To verify your wok in previous section, you can view the content of hello.txt
by typing:
% cat hello.txt
The cat command is useful for displaying short files of a few lines. To display longer files
use less or more commands.
7. Copying Files
cp (copy)
The cp command allows you to copy a file from one location to another location. There are
different syntaxes to use cp command as shown below:
Syntax 1: ( copy a file to another file)
% cp file1 file2
where file1 is the name of an existing file and file2 is the name for the new copy of that
file. The original file will remain unchanged and a copy will be placed in file2. If file1
and file2 are not in current directory, then you have to specify its pathname.
Example2: To copy the file named “salam.txt” to the directory names “ics431”, type:
% cp salam.txt ..
Why!!? Now to see the file you have just copied, type:
% ls ..
Example3: To copy the file named “salam.txt” from directory “ics431” to your current
directory named as “salam.bak”, type
% cp ../salam.txt salam.bak
Why!!? Now to see the file you have just copied, type:
% ls
Exercise (1d): Copy the file named “Hello.txt” to your home directory? Verify your work.
8. Moving Files
mv (move)
To move a file from one place to another, use the mv command. This has the effect of moving
rather than copying the file, so you end up with only one file rather than two.
It can also be used to rename a file, by moving the file to the same directory, but giving it a
different name.
Example: We are going to move the file “salam.bak” to your backup directory, type
% mv salam.bak backup
Now what is the content of your current directory? What is the content of your backup directory?
Example 1: We know that your backup directory contains two files named “salam.txt” and
“salam.bak”. We are going to delete the file “salam.txt” and, as an exercise, delete the second
file.
% rm backup/salam.txt
Example 2: If you successfully delete the two files, you can delete the backup directory. To
delete the backup directory, type:
% rmdir backup
Exercises (1e):
1. Delete the file named “salam.txt” from directory “ics431”
2. create a directory named “tempdir” by using mkdir then remove it.
Exercises
Note: