0% found this document useful (0 votes)
95 views61 pages

(Trinity Institute OF Professional Studies

Linux is a free and open-source operating system based on Unix. It has a hierarchical file structure organized as a tree with directories at the top and files at the bottom. The root directory is at the top. Key components of Linux include the kernel, system library, hardware layer, system utilities, and shell. Linux offers advantages like being free, stable, secure, and scalable. Unix is a multiuser, multitasking operating system developed in the 1970s. It has a layered architecture consisting of hardware, kernel, shell/utilities, and applications. Features include multitasking, multiuser access, portability, and stability.

Uploaded by

minnasahi7
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)
95 views61 pages

(Trinity Institute OF Professional Studies

Linux is a free and open-source operating system based on Unix. It has a hierarchical file structure organized as a tree with directories at the top and files at the bottom. The root directory is at the top. Key components of Linux include the kernel, system library, hardware layer, system utilities, and shell. Linux offers advantages like being free, stable, secure, and scalable. Unix is a multiuser, multitasking operating system developed in the 1970s. It has a layered architecture consisting of hardware, kernel, shell/utilities, and applications. Features include multitasking, multiuser access, portability, and stability.

Uploaded by

minnasahi7
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/ 61

[TRINITY INSTITUTE OF PROFESSIONAL

STUDIES
SEC-9 DWARKA, NEW DELHI- 110075

(AFFILIATED TO)
GURU GOBIND SINGH INDRAPRASTHA
UNIVERSITY SECTOR-16C, DWARKA, NEW DELHI

LINUX – OS LAB
BCA - 371
2021-2024
SUBMITTED BY: SUBMITTED TO:
Prince kumar Ms. Nishika
Enrollment: 05224002021 Assistant Professor
INDEX

S.NO PRACTICAL Date Page SIGNATURE


No
1
Study of Linux, Unix and Windows Operating System.

2 To understand help commands like:- man , info ,help


,whatis ,apropos
3 To understand basic directory navigation commands
like cat, cd, mv, cp, rm, mkdir, rmdir ,file, pwd
command.
4 To understand basic commands like:- date, cal, echo,
bc, ls, who ,whoami , hostname, uname, tty,aliase

5 To understand process related commands like: -ps,


top, pstree, nice, renice in Linux.

6 To understand how to examine and change File


permissions.
7 Set a file to be read-only with the chmod
command. Interpret the file permissions displayed
by the ls -l command.
8 Delete one or more directories with the rmdir
command. See what happens if the directory is not
empty. Experiment (carefully!) with the rm -r
command
to delete a directory and its content.
9 Change your directory to the directory exercises. Create a
file in that directory, named the file as example1 using the
cat command containing the following text: water, water
everywhere and all the boards did shrink; water, water
everywhere, no drop to drink.
10 To understand vi basics, Three modes of vi Editor,
how to write, save, execute a shell scriptin vi editor
11 Write basic shell script to display the table of a
number.
12 Write basic shell script to input a character from
user and then check whether it uppercase, lowercase
or digit.
13 Write basic shell script to calculate factorial of a
number.
14 Write a program to find whether a number is even
or odd.
15 Write basic shell script to list all directories

16 Write basic shell script to display greatest of three


numbers.
17 Write basic shell script to check whether the
number entered by user is prime or not.
18 Write a program to determine whether a string is
palindrome or not.
19 Write a program to find the Fibonacci series.
20 Write a program to find whether a number is even or
odd.
Practical-1
AIM: Study of Linux, Unix and Windows Operating System.

Introduction to Linux
Linux is a free and open-source operating system that is based on Unix. It is developed and
maintained by a community of volunteers around the world. Linux is available in a variety of
distributions, each with its own focus and features. Linux is popular among both home users and
enterprise users.
History
Linux was created by Linus Torvalds in 1991 as a hobby project. He was inspired by Unix, but
he wanted to create an operating system that was free and open source. Torvalds released the first
version of Linux to the public in 1991, and it quickly gained popularity among computer
enthusiasts.
Architecture
Linux is a monolithic kernel-based operating system. This means that the kernel is the core of the
operating system and it is responsible for managing all of the system's resources, including the
CPU, memory, and peripherals. The kernel also provides a set of system calls that allow
applications to interact with the operating system.

Features
Linux is a powerful and versatile operating system that offers a wide range of features,
including:
 Stability and reliability: Linux is known for its stability and reliability. It is often used
for servers and workstations because it can run for long periods of time without crashing.
 Security: Linux is also known for its security. It has a number of security features built
in, such as user permissions and access control lists.
 Scalability: Linux is a scalable operating system. This means that it can be used on a
variety of hardware platforms, from small embedded devices to large supercomputers.
 Open source: Linux is an open-source operating system. This means that the source
code is freely available and anyone can modify it and redistribute it.
Diagram
Here is a diagram of the basic Linux architecture:
The Linux operating system's architecture mainly contains some of the components: the Kernel,
System Library, Hardware layer, System, and Shell utility.

1. Kernel: Kernel is the core of the Linux based operating system. It virtualizes the common
hardware resources of the computer to provide each process with its virtual resources. This
makes the process seem as if it is the sole process running on the machine.
2. System Library: Is the special types of functions that are used to implement the functionality
of the operating system.
3. Shell: It is an interface to the kernel which hides the complexity of the kernel’s functions from
the users. It takes commands from the user and executes the kernel’s functions.
4. Hardware Layer: This layer consists all peripheral devices like RAM/ HDD/ CPU etc.
5. System Utility: It provides the functionalities of an operating system to the user.
File Structure
Linux has a hierarchical file structure. This means that the file system is organized as a tree, with
directories at the top and files at the bottom. The root directory is the top of the tree and it
contains all of the other directories and files.

Directory structure of Linux:


The following is a basic overview of the Linux directory structure:
/ - Root directory
/boot - Contains the Linux kernel and other files needed to boot the system
/dev - Contains device files for all of the system's hardware devices
/etc - Contains configuration files for the system and its applications
/home - Contains the home directories for all of the system's users
/lib - Contains shared libraries that are used by applications
/media - Contains mount points for removable media devices
/mnt - Contains mount points for other file systems
/opt - Contains optional software packages
/proc - Contains information about the system and its processes
/root - Home directory for the root user
/sbin - Contains system administration utilities
/srv - Contains data for services that are running on the system
/sys - Contains information about the system's hardware devices
/tmp - Contains temporary files
/usr - Contains most of the system's applications and libraries
/var - Contains variable data, such as log files and spool directories

Advantages and Disadvantages of Linux


Advantages:
Free and open source
Stable and reliable
Secure
Scalable
Wide range of features
Large and active
community

Disadvantages:
Not as user-friendly as Windows
Not as many software applications available as Windows
Can be difficult to troubleshoot for new users
Introduction to Unix
Unix is a family of multitasking, multiuser operating systems that descend from the original
Unix developed at Bell Labs in the 1970s. Unix is known for its flexibility, portability, and
stability. It is widely used in servers, workstations, and other enterprise computing environments.
History
Unix was created by Ken Thompson and Dennis Ritchie at Bell Labs in the early 1970s.
Thompson was inspired by the Multics operating system, but he wanted to create a simpler and
more efficient operating system. Ritchie developed the C programming language to make it
easier to write Unix programs. Unix was released to the public in 1973, and it quickly gained
popularity among computer scientists and researchers.
Architecture
Unix is a monolithic kernel-based operating system. This means that the kernel is the core of the
operating system and it is responsible for managing all of the system's resources, including the
CPU, memory, and peripherals. The kernel also provides a set of system calls that allow
applications to interact with the operating system.

Features
Unix is a powerful and versatile operating system that offers a wide range of features,
including:
 Multitasking: Unix allows multiple users to run multiple programs simultaneously.
 Multiuser: Unix allows multiple users to log in to the system and use its resources.
 Portability: Unix is written in C, which makes it easy to port to different hardware
platforms.
 Stability: Unix is known for its stability and reliability. It can run for long periods of
time without crashing.
 Security: Unix has a number of security features built in, such as user permissions and
access control lists.
Diagram
Here is a diagram of the basic Unix architecture:
The Linux operating system's architecture mainly contains some of the components: Kernel,
Hardware System, Shell and Utilities and Applications.

1. Hardware: This layer of UNIX consists of all hardware-related information in the UNIX
environment.
2. Kernel: The core of the operating system that's liable for maintaining the full functionality is
named the kernel. The kernel of UNIX runs on the particular machine hardware and interacts
with the hardware effectively.
3. Shell: The shell is a command-line interpreter that allows users to interact with the Unix
operating system. The shell interprets user commands and executes them.
4. Applications: Applications are programs that run on the Unix operating system. Applications
can be used for a variety of purposes, such as web browsing, word processing, and
programming.
File Structure
Unix has a hierarchical file structure. This means that the file system is organized as a tree, with
directories at the top and files at the bottom. The root directory is the top of the tree and it
contains all of the other directories and files.

Directory Structure
The following is a basic overview of the Unix directory structure:
/ - Root directory
/bin - Contains essential command-line utilities
/boot - Contains the Linux kernel and other files needed to boot the system
/dev - Contains device files for all of the system's hardware devices
/etc - Contains configuration files for the system and its applications
/home - Contains the home directories for all of the system's users
/lib - Contains shared libraries that are used by applications
/media - Contains mount points for removable media devices
/mnt - Contains mount points for other file systems
/opt - Contains optional software packages
/proc - Contains information about the system and its processes
/root - Home directory for the root user
/sbin - Contains system administration utilities
/srv - Contains data for services that are running on the system
/sys - Contains information about the system's hardware devices
/tmp - Contains temporary files
/usr - Contains most of the system's applications and libraries
/var - Contains variable data, such as log files and spool directories

Advantages and Disadvantages of Unix


Advantages:
Powerful and
versatile Stable and
reliable Secure
Portable
Open source
Large and active community
Disadvantages:
Can be difficult to learn for new users
Not as user-friendly as Windows
Not as many software applications available as Windows
Introduction to Windows
Windows is a family of proprietary graphical operating systems developed by Microsoft. It is the
most popular operating system for personal computers. Windows is known for its user-friendly
interface and wide range of software compatibility.

History
The first version of Windows, Windows 1.0, was released in 1985. Windows was initially a
graphical user interface (GUI) for MS-DOS, but it eventually evolved into a standalone
operating system. Windows has become increasingly popular over the years, and it is now the
most popular operating system in the world.

Architecture
Windows is a monolithic kernel-based operating system. This means that the kernel is the core of
the operating system and it is responsible for managing all of the system's resources, including
the CPU, memory, and peripherals. The kernel also provides a set of system calls that allow
applications to interact with the operating system.

Features
Windows offers a wide range of features, including:
1. User-friendly interface: Windows has a user-friendly interface that is easy to learn and
use.
2. Wide range of software compatibility: Windows has a wide range of software
compatibility. There are millions of software applications available for Windows.
3. Hardware compatibility: Windows has wide range of hardware compatibility. Most
hardware devices will work with Windows.
4. Security: Windows has a number of security features built in, such as user permissions
and access control lists.
5. Networking: Windows has built-in networking support. This makes it easy to connect to
other computers and networks.
Diagram
Here is a diagram of the basic Windows architecture:
The Windows operating system's architecture mainly contains some of the components:
Kernel, Sub-System, Kernel-mode Subsystem, User-mode Subsystem, and Application

1. Kernel: The kernel is the core of the Windows operating system. It is responsible for
managing all of the system's resources, including the CPU, memory, and peripherals. The
kernel also provides a set of system calls that allow applications to interact with the
operating system.
2. Subsystems: The Windows kernel provides a layer of abstraction called the subsystem
layer. This layer allows applications to run on Windows without having to know the
details of the underlying hardware or kernel. There are two main types of subsystems in
Windows: user-mode subsystems and kernel-mode subsystems.
3. User-mode subsystems: User-mode subsystems provide an environment for applications
to run in user mode. User mode is a less privileged mode than kernel mode, and it is more
secure. The two main user-mode subsystems in Windows are the Win32 subsystem and
the POSIX subsystem.
4. Kernel-mode subsystems: Kernel-mode subsystems provide an environment for
applications to run in kernel mode. Kernel mode is a more privileged mode than user
mode, and it allows applications to access more system resources. The two main kernel-
mode subsystems in Windows are the Windows Driver Model (WDM) subsystem and the
Graphics Device Interface (GDI) subsystem.
5. Applications: Applications are programs that run on the Windows operating system.
Applications can be used for a variety of purposes, such as web browsing, word
processing, and programming. Windows applications are typically written in C++, C#, or
Visual Basic
.NET.

File Structure
Windows has a hierarchical file structure. This means that the file system is organized as a tree,
with directories at the top and files at the bottom. The root directory is the top of the tree and it
contains all of the other directories and files.
Directory Structure
The following is a basic overview of the Windows directory structure:
C:\ - Root directory
C:\Windows - Contains Windows system files
C:\Program Files - Contains program files for installed applications
C:\Users - Contains user profiles and folders
Advantages and Disadvantages of Windows

Advantages:

User-friendly interface
Wide range of software compatibility
Wide range of hardware
compatibility Built-in networking
support
Security features

Disadvantages:

Not as customizable as Linux


Not as free and open source as Linux
Can be more expensive than Linux
Can be more resource-intensive than Linux
Practical 2
AIM: To understand help commands like: -man, info, help, whatis, apropos

1. man: display the user manual

SYNTAX:

$ man [OPTION]... [COMMAND NAME]...

DESCRIPITON:

This command in Linux is used to display the user manual of any command that we can run on the
terminal. It provides a detailed view of the command which includes NAME, SYNOPSIS,
DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS,
EXAMPLES, AUTHORS and SEE ALSO.

OPTIONS:

 No Option: It displays the whole manual of the command.


 Section-num: Since a manual is divided into multiple sections so this option is used to display
only a specific section of a manual.
 -f option: One may not be able to remember the sections in which a command is present.
 -a option: This option helps us to display all the available intro manual pages in succession.
 -k option: This option searches the given command as a regular expression in all the manuals and
it returns the manual pages with the section number in which it is found.
 -I option: It considers the command as case sensitive.
 -w option: This option returns the location in which the manual page of a given command is
present.

OUTPUT:
2. info: give detailed information

SYANTAX:

$ info [OPTION]... [MENU-ITEM...]

DESCRIPTION:

This command reads documentation in the info format. It will give detailed information for a command
when compared with the man page.

OPTIONS:

 -a, –all: It use all matching manuals.


 -k, –apropos=STRING: It look up STRING in all indices of all manuals.
 -d, –directory=DIR: It add DIR to INFOPATH.
 -f, –file=MANUAL: It specify Info manual to visit.
 -h, –help: It display this help and exit.
 -n, –node=NODENAME: It specify nodes in first visited Info file.
 -o, –output=FILE: It output selected nodes to FILE.
 -O, –show-options, –usage: It go to command-line options node.
 -v, –variable VAR=VALUE: It assign VALUE to Info variable VAR.
 –version: It display version information and exit.
 -w, –where, –location: It print physical location of Info file.

OUTPUTS:

3. help: learn about any built-in command.

SYNTAX:

$ help [-dms] [pattern ...]

DESCRIPITON:

This command just displays information about shell built-in commands.


 OPTIONS:
 -d option : It is used when you just want to get an overview about any shell built-in command i.e
it only gives short description.
 -m option : It displays usage in pseudo-manpage format.
 -s option : It just displays only a short usage synopsis for each topic matching.

OUTPUT:

4. whatis: one-line manual page description

SYNTAX:

$ whatis [option] [command_name]

DESCRIPITON:

This command in Linux is used to get a one-line manual page description. In Linux, each manual page has
some sort of description within it. So, this command search for the manual pages names and show the
manual page description of the specified filename or argument.
OPTIONS:

 `-d`: This option prints the debugging information.


 `-v’: This option will print verbose warning messages.
 -h: it gives the general syntax along with the various options that can be used.
 `-C`: This option uses this user configuration file rather than the default of ~/.manpath.
 ` -?`: Yet another option with the help of which you can print a help message.
 `-V`:This option will display version information.

OUTPUT:

5. apropos: find the command and its functions

SYNTAX:

apropos [OPTION..] KEYWORD...

DESCRIPITON:

It searches the Linux man page with the help of the keyword provided by the user to find the command and
its functions.

OPTIONS:
 -d: This option is used to emit debugging messages. When this option is used then terminal returns
man directories, global path, path directory, warnings, etc. of each command which is related to
the search keyword.
 -v: This option is used to print verbose warning messages.
 -e, –exact: This option is used to search each keyword for exact match.
 -V, –version: Used to print program version
 -C: This option is used when we don’t want to use the default(/manpath) but user configuration file.
 -L: Define the locale for this search.

OUTPUT:
Program-3
AIM: To understand basic directory navigation commands like cat, cd, mv, cp,
rm, mkdir, file, pwd command.

1. cat: create file, display contents, append file and concatenate two files.

SYNTAX:

$ cat [OPTION] [FILE NAME].

DESCRIPTION:

cat is one of the most common commands in Linux. It is mainly used to


 Copy text files.
 Combine text files.
 Create new text files
 Display text files on screen
 Append those files
Ctrl+d to exit after adding contents.

OPTIONS:

 cat > filename: This command is used to create files in current directory and would allow adding
contents to it (after pressing ‘enter’).
 cat filename: This command is used to display content of files.
 cat filename1 filename2 destination filename: concatenate file1 & file2 and add to destination
file.
 cat>>filename: append the contents.

OUTPUT:
2. cd: change directory

SYNTAX:

$ cd [directory]

DESCRIPTION:

cd command in Linux known as the change directory command. It is used to move efficiently from the
current working directory to different directories in our System.

OPTIONS:
 cd [directory name]: This command is used to move inside a directory.
 cd dir_1/dir_2/dir_3: This command is used to move inside a directory from a directory.

OUTPUT:
3. mv: rename a file or directory.

SYNTAX:

$ mv [OPTION]... OLDNAME NEWNAME

DESCRIPTION:

This command is used to rename or move a file. This command can also be a user to move
a file from one directory to another. It does not create copy of the file, it merely renames it.

OPTIONS:

 mv oldfile newfile: It is used for moving the contents of oldfile name to newfile name.
 mv file1 flie2 dir1: move file1 and file2 to the directory dir1.

OUTPUT:

4. cp: copy file

SYNTAX:

$ cp filename1......filename n

DESCRIPTION:

This command is used to copies a file or group of files to another file. It simply creates an
image of the file with different name.

OPTIONS:
 cp file1 file2: It copies file1 into file2.
 cp file1 dir1: create a copy in directory dir1 with file name file.
 -i: interactive copy
 -r: recursive copy

OUTPUT:

5. rm: Delete file.

SYNTAX:

$ rm [OPTION] [FILE NAME1 FILENAME2].

DESCRIPTION:

Delete a file or more than one files. rm* deletes all files of directory. Once deleted filed
file can never be restored.

OPTIONS:
 -i: interactive deletion of file i.e. prompts for asking whether to delete file or not.
 -r: recursive deletion i.e. deletes all directory, sub-directory and name of current directory.

OUTPUT:
6. mkdir: create directories.

SYNTAX:

mkdir [options...] [directories ...]

DESCRIPTION:

This command in Linux allows the user to create directories (also referred to as folders in some operating
systems). This command can create multiple directories at once as well as set the permissions for the
directories.

OPTIONS:
 –help: It displays help-related information and exits.
 –version: It displays the version number, some information regarding the license and exits.
 -v or –verbose: It displays a message for every directory created.
 -p: A flag which enables the command to create parent directories as necessary. If the directories
exist, no error is specified.
 -m: This option is used to set the file modes, i.e. permissions, etc. for the created directories. The
syntax of the mode is the same as the chmod command.

OUTPUT:

7. file: determine the type of a file.


SYNTAX:

file [option] [filename]

DESCRIPITION:

This command is used to determine the type of a file. .file type may be of human-readable(e.g. ‘ASCII
text’) or MIME type(e.g. ‘text/plain; charset=us-ascii’). This command tests each argument in an attempt
to categorize it.

OPTIONS:
 -b, –brief : This is used to display just file type in brief mode.
 * : Command displays the all files’s file type.
 [range]* : To display the file type of files in specific range.
 -s : For special files
 -N : Don’t pad filenames so that they align in the output
 -i : To view mime type of file.
 -c : Cause a checking printout of the parsed form of the magic file.
 -z : Try to look inside compressed files.
 filenames: Displays file types of multiple files

OUTPUT:
8. pwd: print the path of working directory

SYNTAX:

pwd [OPTIONS]

DESCRIPITON:

pwd stands for Print Working Directory. It prints the path of the working directory, starting from the root.

OPTIONS:

 pwd -L: Prints the symbolic path.


 pwd -P: Prints the actual path.

OUTPUT:
Program-4
AIM: To understand basic commands like: date, cal, echo, bc, ls, who, whoami ,
hostname, uname, tty

1. date: display system time and date.

SYNTAX:

date [OPTION]... [+FORMAT]


date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

DESCRIPITON:

This command is used to display the system date and time. date command is also used to set date and time
of the system. By default the date command displays the date in the time zone on which unix/linux
operating system is configured.

OPTIONS:

date (no option): With no options, the date command displays the current date and time, including the
abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the time
zone name, and the year.

-u Option: Displays the time in GMT(Greenwich Mean Time)/UTC(Coordinated Universal Time )time
zone.

–date or -d Option: Displays the given date string in the format of date.

-s or –set Option: To set the system date and time -s or –set option is used.

–file or -f Option: This is used to display the date string present at each line of file in the date and time
format.

-r Option: This is used to display the last modified timestamp of a datefile .

OUTPUT:
2. cal: see the calendar.

SYNTAX:

cal [ [ month ] year]

DESCRIPITION:

cal command is a calendar command in Linux which is used to see the calendar of a specific month or a
whole year.

OPTIONS:
 cal : Shows current month calendar on the terminal with the current date highlighted.
 cal -y : Shows the calendar of the complete current year with the current date highlighted.
 cal -3 : Shows calendar of previous, current and next month.

OUTPUT:

3. echo: display lines of text or strings

SYNTAX:

echo [option] [string]

DESCRIPITION:

The echo command in Linux is a built-in command that allows users to display lines of text or strings that
are passed as arguments.

OPTIONS:
 \b : it removes all the spaces in between the text.
 \c : suppress trailing new line with backspace interpreter ‘-e‘ to continue without emitting new line.
 \n : this option creates a new line from where it is used.
 \t : this option is used to create horizontal tab spaces.
 \r : carriage return with backspace interpreter ‘-e‘ to have specified carriage return in output.
 \v : this option is used to create vertical tab spaces.
 \a : alert return with backspace interpreter ‘-e‘ to have sound alert.
 echo *: this command will print all files/folders, similar to ls command.

OUTPUT:
4. bc: command line calculator.

SYNTAX:

bc [ -hlwsqv ] [long-options] [ file ... ]

DESCRIPTION:

This command is used for command line calculator. It is similar to basic calculator by using which we can
do basic mathematical calculations.

OPTIONS:

 -h, {- -help } : Print the usage and exit.


 -i, {- -interactive } : Force interactive mode.
 -l, {- -mathlib } : Define the standard math library.
 -w, {- -warn } : Give warnings for extensions to POSIX bc.
 -s, {- -standard } : Process exactly the POSIX bc language.
 -q, {- -quiet } : Do not print the normal GNU bc welcome.
 -v, {- -version } : Print the version number and copyright and quit.

OUTPUT:
5. ls: list directory

SYNTAX:

ls [option] [file/directory]

DESCRIPTION:

ls is a Linux shell command that lists directory contents of files and directories. It provides valuable
information about files, directories, and their attributes.

OPTIONS:
 -l known as a long format that displays detailed information about files and directories.
 -a Represent all files Include hidden files and directories in the listing.
 -t Sort files and directories by their last modification time, displaying the most recently
modified ones first.
 -r known as reverse order which is used to reverse the default order of listing.
 -S Sort files and directories by their sizes, listing the largest ones first.
 -R List files and directories recursively, including subdirectories.
 -i known as inode which displays the index number (inode) of each file and directory.
 -g known as group which displays the group ownership of files and directories instead of the
owner.
 -h Print file sizes in human-readable format (e.g., 1K, 234M, 2G).
 -d List directories themselves, rather than their contents.

OUTPUT:

6. who: find out the information.

SYNTAX:

$who [options] [filename]

DESCRIPTION:

The who command is used to get information about currently logged in user on to system.

OPTIONS:
$ who -m -H: To display host name and user associated with standard input such as keyboard
$ who -p -H: To show all active processes which are spawned by INIT process
$ who -T -H: To show status of the users message as +, – or ?
$ who -u: To show list of users logged in to system.

OUTPUT:

7. whoami: displays the username of the current user.

SYANTAX:
$ whoami

DESCRIPITON:

 It is basically the concatenation of the strings “who”,”am”,”i” as whoami.


 It displays the username of the current user when this command is invoked.
 It is similar as running the id command with the options -un.
OPTIONS:
–help : It gives the help message and exit.
–version Option : It gives the version information and exit.

OUTPUT:
8. hostname: uniquely identify over a network

SYNTAX:

hostname -[option] [file]

DESCRIPTION:

A hostname is a name given to a computer and attached to the network. Its main purpose is to uniquely
identify over a network.

OPTIONS:
-a: This option is used to get the alias name of the host system (if any)
-b: Used to always set a hostname. Default name is used if none specified.
-d : This option is used to get the Domain if local domains are set.
-i: This option is used to get the IP (network) addresses.
-V: Gives version number as output.

OUTPUT:

9. uname: display system infrormantion.

SYANTAX:

$ uname [OPTION]

DESCRIPITION:

The command ‘uname‘ displays the information about the system.

OPTIONS:

-a option: It prints all the system information in the following order: Kernel name, network node
hostname, kernel release date, kernel version, machine hardware name, hardware platform, operating
system
-s option: It prints the kernel name.
-n option: It prints the hostname of the network node(current computer).
-r option: It prints the kernel release date.
-v option: It prints the version of the current kernel.
-o option: It prints the name of the operating system.

OUTPUT:

10. tty: teletype as a terminal

SYNTAX:

$ tty [OPTION]....

DESCRIPITON:

tty which displays information related to the terminal. The tty command of the terminal basically prints
the file name of the terminal connected to standard input.

OPTIONS:

-s, ––silent, ––quiet: Prints nothing, only returns an exit status.


-a:which displays the name of all currently active terminals,
-h: which displays the full path name of the terminal device file. ––
help: It will display the help message and exit.
––version: Prints the version information and exits.

OUTPUT:
Program-5
AIM: To understand process related commands like: - ps, top, pstree, nice, renice in
Linux.

1. ps: Process Status

SYNTAX:
ps [options]

DESCRIPTION:

it allows multiple processes to operate simultaneously without interfering with each other
Process is one of the important fundamental concept of the Linux OS.
A process is an executing instance of a program and carry out different tasks within the operating system.

OPTIONS:

-ps Simple process selection : Shows the processes for the current shell
-e -a View Processes : View all the running processes use either of the following option with ps –
-T: View all processes associated with this terminal
-r : View all the running processes

OUTPUT:

2 top: show linux processes.

SYNTAX:
$ top [options]

DESCRIPTION:

 The top command displays all the running process within the environment of your system.
 It helps in monitoring system usage and performances.
 It is mainly used to detect load on the server by system administrators.
OPTIONS:

 -a This option is used to solve the processes according to the allocated memory.
 -b It begins the top command in batch mode, which can be helpful in sending results from the
top command to other files and programs.
 -c It begins the top command with the last remembered state reversed 'c'.
 -d It shows the delay between the screen updates and then overrides the associated value in
the startup default or personal configuration file of one.
 -h It shows the usage prompt and library version, then quit.
 -H It begins a top command with the last remembered state reversed 'H'.
 -i It begins a top command with the last remembered state reversed i.

OUTPUT:

3. pstree: show running process as a tree.

SYNTAX:
pstree [options] [pid or username]

DESCRIPTION:

Pstree command in Linux that shows the running processes as a tree which is a more convenient way to
display the processes hierarchy and makes the output more visually appealing. The root of the tree is
either init or the process with the given pid. Pstree can also be installed in other Unix systems.

OPTIONS:

pstree: To display process tree


pstree -a: To include command line arguments in output
psstree -p: To display PIDs
pstree -c: To force pstree to expand identical subtrees in output.
pstree -n: To sort processes.
pstree -u: To see who is the owner/user of a process.

OUTPUT:
4. nice: prioritize the execution of program.

SYNTAX:
$ nice [options]:

DESCRIPTION:

nice command in Linux helps in execution of a program/process with modified scheduling priority. It
launches a process with a user-defined scheduling priority. In this, if we give a process a higher priority,
then Kernel will allocate more CPU time to that process.

OPTIONS:

-nice -10 gnome-terminal: To set the priority of a process


-nice –10 gnome-terminal: To set the negative priority for a process

OUTPUT:

5. renice : allow you to modify running program.

SYNTAX:
$ renice [options]:

DESCRIPTION:

Whereas the renice command allows you to change and modify the scheduling priority of an already
running process. Linux Kernel schedules the process and allocates CPU time accordingly for each
of them.

OPTIONS:

sudo renice -n 15 -p 77982: changing priority of the running process.


renice -n 10 -g 4 : To change the priority of all programs of a specific group.
sudo renice -n 10 -u 2 : To change the priority of all programs of a specific user.

OUTPUT:
Program-6
AIM: To understand how to examine and change File permissions.
To examine and change file permissions, you can use the following steps:

Open a terminal window.

Run the following command:

ls –l

This command will list all of the files and directories in the current directory, along with their
permissions.

To change file permissions:

Open a terminal window.

Navigate to the directory that contains the file that you want to change the permissions for.

Run the following command:

chmod [permissions] [filename]


For example, to specify read and write permissions, you would use the octal code 6.

For example, to change the permissions for the file example.txt to read and write permissions for the user,
and read permissions for the group and others, you would run the following command:

chmod 644 example.txt


Program-7
AIM: Set a file to be read-only with the chmod command. Interpret the file
permissions displayedbythe ls -l command.
To set a file to be read-only with the chmod command, you can use the following steps:

Open a terminal window.

1. Navigate to the directory that contains the file that you want to set to be read-only.
2. Run the chmod command, followed by the octal permission code for read-only permissions
3. The octal permission code for read-only permissions is 400.

For example, to set the file example.txt to be read-only, you would run the following command:
chmod 400 example.txt

The following output of the ls -l command shows that the file example.txt has read-only permissions for the
user, read permissions for the group, and no permissions for others.
Program-8
AIM: Delete one or more directories with the rmdir command. See what happens if
the directory is not empty. Experiment (carefully!) with the rm -r command to delete
a directory and its content.
To delete one or more directories with the rmdir command, you can use the following steps:

Open a terminal window.

Navigate to the directory that you want to delete.

Run the rmdir command, followed by the name of the directory that you want to delete.

For example, to delete the exercises directory, you would run the following command:
rmdir exercises

If the directory is empty, the rmdir command will delete the directory successfully. However, if the
directory is not empty, the rmdir command will fail.

To experiment with the rm -r command, you can create a test directory and add some files to it. Then, you
can run the rm -r command to delete the directory and its contents.

For example, you could create a test directory called test_dir and add the following files to it:

test_dir/file1.txt
test_dir/file2.txt
Then, you could run the following command to delete the directory and its contents:

rm -r test_dir

This command will delete the test_dir directory and all of its contents, including the file1.txt and file2.txt
files.

WARNING: The rm -r command is very powerful and can be dangerous if used incorrectly. Be careful
when using this command, and make sure that you understand what you are doing before you run it.
Program-9
AIM: Change your directory to the directory exercises. Create a file in that directory,
named the file as example1 using the cat command containing the following text:
water, water everywhere and all the boards did shrink; water, water everywhere, no
drop to drink.
Steps: First make a directory name as “exercises” in which you create a file (example1)

After, you create a directory verify that. It is created or not

Explanation of the command:

cd exercises && cat > example1 << EOF

water, water everywhere and all the boards did shrink; water, water everywhere, no drop to drink.

EOF

cd exercises: This changes the current directory to the exercises directory.

&&: This is a logical operator that means "and then." It tells the operating system to execute the next
command only if the previous command was successful.

cat: This is a command-line tool that creates, reads, and concatenates files. In this case, we are using it to
create a new file named example1.

>: This is a redirection operator that tells the operating system to write the output of the command to the
specified file. In this case, we are telling the operating system to write the output of the cat command to
the file example1.

<< EOF: This is a heredoc operator that tells the operating system to read the text from the current line
until it reaches the EOF marker. The EOF marker is a special marker that indicates the end of the text. In
this case, the text is the following:
water, water everywhere and all the boards did shrink; water, water everywhere, no drop to drink.

Once the operating system reaches the EOF marker, it will stop reading the text and execute the cat
command.

The output of the cat command is the text that we specified in the heredoc operator. This text is written to
the file example1.

Output:
Program-10
AIM: To understand vi basics, three modes of vi Editor, how to write, save, execute a
shell script in vi editor

VI (Visual Editor)

The default editor that comes with the LINUX operating system is called vi (visual editor). Using vi
editor, we can edit an existing file or create a new file from scratch. we can also use this editor to just
read a text file. The advanced version of the vi editor is the VIM editor.

Command Description

i Inserts text before current cursor location

a Insert text after current cursor location

A Insert text at the end of current line

o Creates a new line for text entry below cursor location and switches to insert
mode.

O Creates a new line for text entry above cursor location and switches to insert
mode.

s Replaces single character under the cursor with any number of characters and
switches to insert mode.

R Overwrites text from the cursor to the right, without switching to insert mode.
Arithmetic Operators

Operator Example
+ (Addition) `expr $a + $b` will give 30
- (Subtraction) `expr $a - $b` will give -10
* (Multiplication) `expr $a \* $b` will give 200
/ (Division) `expr $b / $a` will give 2
% (Modulus) `expr $b % $a` will give 0
= (Assignment) a = $b would assign value of b into a
== (Equality) [ $a == $b ] would return false.
!= (Not Equality) [ $a != $b ] would return true.

Relational Operators

Operator Example
-eq [ $a -eq $b ] is not true.

-ne [ $a -ne $b ] is true.

-gt [ $a -gt $b ] is not true.

-lt [ $a -lt $b ] is true.

-ge [ $a -ge $b ] is not true.

-le [ $a -le $b ] is true.

Boolean Operators

Operator Example
! [ ! false ] is true.

-o [ $a -lt 20 -o $b -gt 100 ] is true.

-a This is logical AND. If both the operands are true, then the condition becomes true otherwise
false. [ $a -lt 20 -a $b -gt 100 ] is false.

String Operators

The following string operators are supported by Bourne Shell.

Assume variable a holds "abc" and variable b holds "efg" then −

Show Examples

Operator Description Example

= Checks if the value of two operands are equal or not; if yes, then the condition becomes true
.[ $a = $b ] is not true.
!= Checks if the value of two operands are equal or not; if values are not equal then the condition
becomes true. [ $a != $b ] is true.

-z Checks if the given string operand size is zero; if it is zero length, then it returns true. [ -z $a ]
is not true.

-n Checks if the given string operand size is non-zero; if it is nonzero length, then it returns true. [
-n $a ] is not false.

str Checks if str is not the empty string; if it is empty, then it returns false.[ $a ] is not false.
File Test Operators

We have a few operators that can be used to test various properties associated with a Unix file.

Assume a variable file holds an existing file name "test" the size of which is 100 bytes and has read, write
and execute permission on −

Show Examples

Operator Description Example

-b file Checks if file is a block special file; if yes, then the condition becomes true. [ -b $file ] is
false.

-c file Checks if file is a character special file; if yes, then the condition becomes true. [ -c $file ] is
false.

-d file Checks if file is a directory; if yes, then the condition becomes true.[ -d $file ] is not true.

-f file Checks if file is an ordinary file as opposed to a directory or special file; if yes, then the condition
becomes true. [ -f $file ] is true.

-g file Checks if file has its set group ID (SGID) bit set; if yes, then the condition becomes true.
[ -g $file ] is false.

-k file Checks if file has its sticky bit set; if yes, then the condition becomes true. [ -k $file ] is false.

-p file Checks if file is a named pipe; if yes, then the condition becomes true. [ -p $file ] is false.

-t file Checks if file descriptor is open and associated with a terminal; if yes, then the condition becomes
true.[ -t $file ] is false.

-u file Checks if file has its Set User ID (SUID) bit set; if yes, then the condition becomes true.
[ -u $file ] is false.

-r file Checks if file is readable; if yes, then the condition becomes true. [ -r $file ] is true.

-w file Checks if file is writable; if yes, then the condition becomes true. [ -w $file ] is true.

-x file Checks if file is executable; if yes, then the condition becomes true. [ -x $file ] is true.
-s file Checks if file has size greater than 0; if yes, then condition becomes true.[ -s $file ] is true.

-e file Checks if file exists; is true even if file is a directory but exists.[ -e $file ] is true.
loop

The three main modes of vi are:


Command mode: This is the default mode, and it is used to enter commands, such as moving the
cursor, deleting text, and searching for patterns.
Insert mode: This mode is used to insert text into the document.
Visual mode: This mode is used to select and edit text visually.
To switch between modes, you press the ESC key to enter command mode, the I key to enter insert
mode, and the V key to enter visual mode.
To write a shell script in vi, you can simply follow these steps:
Create a new file with the .sh extension.
/home/arjun/Pictures/Screenshots/Screenshot from 2023-10-15 20-56-32.png

Enter command mode and start typing your shell script.


When you are finished, enter command mode and press the : wq command to save the file.

Exit vi and make the shell script executable by running the following command:

chmod +x prime.sh (shell script filename)

To execute the shell script, you can simply run the following command:

./shell_script.sh
Practical-11
AIM: Write basic shell script to display the table of a number.
Source Code :

Output:
Program-12
AIM: Write basic shell script to input a character from user and then check
whether it is uppercase, lowercase or digit.
Source Code :

Output:
Program-13
AIM: Write basic shell script to calculate factorial of a number.
Source Code :

Output:
Program-14
AIM: Write basic shell script to input the month number and generate
corresponding calendar.
Source Code:

Output:
Program-15
AIM: Write basic shell script to list all directories.

Source Code:

Output:
Program-16
AIM: Write basic shell script to display greatest of three numbers.
Source Code :

Output:
Program-17
AIM: Write basic shell script to check whether the number entered by user is
prime or not.
Source Code:

Output:
Program-18
AIM: Write a program to determine whether a string is palindrome or not.
Source Code:

Output:
Program-19

AIM: Write a program to find the Fibonacci series.


Source Code:

Output:
Program-20
AIM: Write a program to find whether a number is even or odd.

Source Code :

Output:

You might also like