0% found this document useful (0 votes)
97 views8 pages

Operating System CS211L Lab - 02 Linux Environment and Introduction To CLI

The document discusses introducing students to the Linux command line interface. It covers logging in and out of Linux, the file system hierarchy including root, home and path directories, and common file and directory commands like ls, cd, mkdir. The key goals are for students to understand the Linux environment, file system structure, and be able to use basic commands to navigate and manage files and directories.

Uploaded by

saqib25492
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views8 pages

Operating System CS211L Lab - 02 Linux Environment and Introduction To CLI

The document discusses introducing students to the Linux command line interface. It covers logging in and out of Linux, the file system hierarchy including root, home and path directories, and common file and directory commands like ls, cd, mkdir. The key goals are for students to understand the Linux environment, file system structure, and be able to use basic commands to navigate and manage files and directories.

Uploaded by

saqib25492
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Operating System CS211L Lab – 02

Linux Environment and Introduction to CLI


In this students will learn about the environment of Linux operating system. File system of Linux
operating system and its hierarchy. They will also learn that “How to log in and log out from
Linux operation system. In this students will learn about the Root Directory, Home Directory,
and Path (absolute or relative). After completion of this lab students will be able to:
 How to Log in and log out of the Linux operating system
 The environment of Linux operating system
 Hierarchy of directory and its file system
 Know the root directory, home directory and paths
 To use the Linux commands.
 To list the files and directories of the current directory.
 To make, remove and change a directory.

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

Linux File System Hierarchy


Unlike DOS, which permits you to organize your folders (directories) and files anyway you
please, the Linux file system is organized into a standard directory structure. A portion of the
Linux directory structure is pictured below:

/(Root Directory)

etc/ bin/ usr/ home/ div/ lib/ info/

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.

Current Working Directory


A directory in which user is currently working.
Pathname
Pathname is a reference to identify a file within the directory structure. For example the
following file name indicates the file in the hierarchy of directories:

/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.

Current Directory (Working Directory)

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

Some standard Linux directories are given below:

/home: Users’ home directory

/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).

File and Directory Management

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.

Common File and Directory Commands


Commonly used directory commands are ls, cd, mkdir, pwd, rmdir, etc and common file
commands include cat, cp, mv, rm, etc.

Exploring the File Hierarchy


When you login, there is a special directory associated with your login name called your home
directory. Your home directory is actually your initial current working directory. The simplest
way to find out where in the directory hierarchy your home directory is located is just to use the
command pwd straight after you login.

The pwd command tells you your present working directory.


$ pwd
/home/your_account_name
Note: - Linux commands are case-sensitive. All standard Linux commands use lower case letters
only.
In order to move away from your home directory to somewhere else in the directory hierarchy,
you use the cd (change directory) command. So, to change to the root directory you would use
the command.

$ 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

And when you enter ls -r on the command prompt.

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

mkdir directory-name Creates a new directory. Directory-name specifies the name


of the new directory. If the name doesn’t begin with a
slash, the new directory is created as a subdirectory of the
current working directory. If the name begins with a slash,
the name defines the path from the root directory to the
new directory.

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 Change to another directory.


For Example:

$cd dir-name

To change to sub-directory under the current directory use the command.


mumtaz@ltsp-server:~$cd books
(when Enter is pressed, the prompt becomes)

mumtaz@ltsp-server:~/books$

Do you see any difference between the two prompts?


Now you are in books directory, a step down to home. How could you go up?

mumtaz@ltsp-server:~/books$ cd .. (there’s space between cd and ..)

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$ mkdir chemistry

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

math physics computer

trigonometry calculus quantum classical nuclear

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.

c) Now recreate both of the removed directories.

You might also like