Operating System CS211L Lab - 02 Linux Environment and Introduction To CLI
Operating System CS211L Lab - 02 Linux Environment and Introduction To CLI
Operating System
Operating System is a type of System Software and is a collection (set) of programs, which
performs two specific functions. First, it provides a user interface so that human user can interact
with the machine. Second, the operating system manages computer resources. It accepts user
commands, and then it detrains, allowing the programs to run where they are loaded into
memory first and communication between various hardware devices is coordinated. Windows,
UNIX, Linux, DOS are popular operating systems.
Linux
Linux is an operating system, which is a flavor of UNIX. Linux is a multi-user and multi-tasking
operating system. Because of the likeness with UNIX, all the programs written for UNIX can be
compiled and run under Linux. Linux operating system runes on variety of machines like
486/Pentium, Sun SPARC, PowerPC, etc. One of the important features of Linux is
communication through TCP/IP protocols.
Linus Torvalds at the University of Helsinki, Finland, developed Linux. UNIX programmers
around the world assisted him in the development of Linux.
Linux System
Linux System can be split into two parts.
i) Shell
ii) Kernel
Formally, a Shell is interface between a user and a Linux operating system, i.e. user interacts
with the Linux operating system through the shell. The shell performs two tasks; it accepts
commands from a user and then interprets those commands.
Two shells, which are commonly used, are Bourne shell and C shell. One other shell, which is
rather complex, is Korn shell.
Kernel is the core of Linux Operating System, which is operational as long as the computer
system is running. The kernel is part of the Linux Operating system which consists of routines
which interact with underlying hardware, and routines which include system calls handling,
process management, scheduling, signals, paging, swapping, the file system, and I/O to storage
devices.
So, shell accepts commands from the user, interprets them and delivers these interpreted
commands to the kernel for execution. After execution, the shell displays results of the executed
commands.
Files
File is a mechanism through which we store information. Normally, there are two modes of
storing information.
i) File
ii) Directories
i) File
A simple file stores some type of information. The information it has may be in text format, or in
binary format.
ii) Directories
Directories are special types of files which contain information about the files stored inside that
directory, and may contain other directories (called Subdirectories). So directories are also files,
which contain some vital information about the files, and other directories.
There’s a file (management) system in an operating system, which manipulates file and
directories. The major operations which can be performed on files and directories are given
below:
· Create
· Delete
· Open
· Close
· Read
· Write
· Append
· Seek
· Rename
· Get Attributes
· Set Attributes
File Attributes
Since file contains some information about something, information about the file itself is also
needed. This information is called file attributes. All operating systems associate some extra
information with each file, for example date and time of when the file was created or modified,
file size etc. These items are called file attributes. Some of the usual file attributes are given
below:
· File Name
· Creator
· Date created
· Date of last read access
· Date of last modification
· Current size of the file in bytes
/(Root Directory)
sbin/ tmp
-----------
bin/ lib/ info/ sbin/
Root Directory
The top most directory is called root directory. The Linux File system hierarchical structure
begins with a root directory. The name of root directory is /.
Home Directory
The directory selected by Linux as the working directory when a user logs on. When a user logs
on, Linux selects home directory (its name usually matches your login name) as his/her
working directory. This is where a user normally performs his routine tasks, stores files and
data. This is where various configuration settings about the user are stored.
/usr/users/bill/letters/pay
The first slash (/) indicates the root directory, moves down to usr, then users, then bill, then
letters and finally to the file pay. So this pathname is a reference to the file pay with respect to
the root directory (/).
A path may be of two types.
Absolute Pathname
Absolute pathname identifies a file or a directory irrespective of the current state of the user. The
user's "current directory" is part of the user's state. The absolute pathname always starts from the
root directory.
For example, to locate filename in lib directory, the absolute path of the file is:
/usr/local/lib/filename
Relative pathname
The pathname which identifies a file or a directory in a way that depends on the state of the user
i.e. users current directory. Relative pathname identifies files with respect to user's current
directory.
Consider the following diagram.
thesis
chapter4.tex
To refer to a file chapter4.tex in the subdirectory thesis with respect to the current directory, we
use pathname.
thesis/chepter4.tex
/etc: All system administrator commands, configuration files, and installation control
files.
/bin: The core set of system commands and programs. Most systems cannot
boot (initially start) without executing some of the commands in this directory.
/dev: The device files used to access system peripherals (for example, your
terminal can be accessed from /dev/tty).
/lib: The standard set of programming libraries required by Linux programs.
/tmp: Temporary files created and used by many Linux programs.
/var: Log files, spool files etc.
/root: The root user’s home directory.
/usr/bin Common commands and programs.
/usr/doc Documentation
/usr/games Games
/usr/include Header files
/usr/info Online documentation
/usr/man Manual pages (help)
/usr/share Shared information
Logging In
As we know that shell is an interface between a user and Linux kernel. The first step that you
must accomplish before you can use the shell is to log in to your machine. This is usually a very
straight forward process provided that you have a login ID and a password
When you login successfully, for an ordinary user account, the system will execute a program
called the shell. And it is your shell process that is responsible for giving you a command
prompt. By default, the prompt for a non-privileged user is a dollar ($) symbol, and for a
privileged (root) user is a hash (#) symbol.
Logging out
Logging out of Linux system is done by typing control-d (^d).
Linux has commands with different syntax or format. You should get used to these commands
because you will be using them frequently. There is syntax for each command, using wrong
syntax the command will not execute. Then we will see the general syntax for all Linux
commands. After completion of the lab students will be able:
Command
A request from a user to the Linux operating system asking that a specific function be performed;
for example, a request to list all files in your current directory. Shell commands operate on files,
directories, and various devices – disks, printers, etc.
$ cd /
Directory Commands
Command Description
ls List the file in the directory, just like dir command in DOS.
Options
-a Display all the files, and subdirectories, including hidden files.
-l Display detailed information about each file, and directory.
-r Display files in the reverse order.
Example
When you enter ls on the command prompt, just after the command cd / .
mumtaz@ltsp-server:/$ ls
bin dev home lib mail mnt proc sbin usr
boot etc initrd lost+found misc opt root tmp var
mumtaz@ltsp-server: /$ ls -r
var tmp root opt misc lost+found initrd etc boot
usr sbin proc mnt mail lib home dev bin
Command Description
Try to use the following command first because this will bring you back to your home directory.
$ cd
Now try mkdir command
mumtaz@ltsp-server:~$ mkdir books
This command will create a new directory under the home directory.
mumtaz@ltsp-server
|
books
Though you have created a sub-directory books, but you are still in the home (parent directory of
books) directory i.e. mumtaz@ltsp-server:~$
How would you go to the directory books?
Command Description
$cd dir-name
mumtaz@ltsp-server:~/books$
Now you will again be in your parent directory. And the prompt becomes:
mumtaz@ltsp-server:~$
Example
Create other directory chemistry under books, and move to chemistry directory.
mumtaz@ltsp-server:~$ cd books
mumtaz@ltsp-server:~/books$ cd chemistry
mumtaz@ltsp-server:~/books/chemistry$
Now you are quite away from your home directory. How would you go to your home directory?
Your current location is
mumtaz@ltsp-server:~$/books / chemistry
To go to your home directory:
mumtaz@ltsp-server:~/books/chemistry$ cd (enter)
The prompt will become:
mumtaz@ltsp-server:~$
Type pwd at prompt see where are you.
Example
Now you are in your home directory. How will you go directly to chemistry directory?
mumtaz@ltsp-server:~$ cd books/chemistry (enter)
What do you think books/chemistry is relative or absolute path?
Make the following directory hierarchy.
Books
Example
If I’m in directory classical, how would find I where I am? The command used for that is pwd.
When I entered this command when I was in directory classical the following information was
printed on my screen. The path printed was absolute path.
How will you add a directory graphics under the directory computer while you are in physics’
sub-directory classical?
Now you can create directories. How do we remove them?
Command Description
rmdir (‘remove directory”) Deletes a directory.
For example
$rmdir dirname
Note:- rmdir will only work if the directory you are trying to remove does not contain any file.
So first remove all files from the directory.
a) You are in books directory, from here try to remove sub-directory quantum under the
directory physics.
b) Now move to directory computer, from here remove sub-directory calculus under the
directory math.