Linux Basic BLP Msbte Manual Msbte Store
Linux Basic BLP Msbte Manual Msbte Store
for
Linux Basics
(312001)
Second Semester
Diploma in Computer Engineering/
Computer Science & Engineering/ Data
Sciences/ Computer Hardware &
Maintenance/Information Technology/
Computer Science & Information
Technology
Maharashtra State
Board of Technical Education, Mumbai
(Autonomous) (ISO-9001-2008) (ISO/IEC 27001:2013)
Maharashtra State
Board of Technical Education, Mumbai
(Autonomous) (ISO-9001-2008) (ISO/IEC 27001:2013)
th
4 Floor, Government Polytechnic Building, 49, Kherwadi,
Bandra (East), Mumbai -400051.
Maharashtra State Board
of Technical Education
Certificate
This is to certify that Mr. / Ms. …………………………………….
Roll No……………………….of Second Semester of Diploma in
………………………………………………..…………. of Institute
………………………………………………………………………..
(Code ………………..) has attained predefined laboratory earning
outcomes (LLOs) satisfactorily in course LINUX BASICS (312001)
for the academic year 20…….to 20…..... as prescribed in the
curriculum.
.Preface
The primary focus of any engineering laboratory/field work in the technical education system is
to develop the much needed industry relevant competencies and skills. With this in view,
MSBTE embarked on this innovative ‘K’ Scheme curricula for engineering Diploma
programmes with outcome-based education as the focus and accordingly, relatively large amount
of time is allotted for the practical work. This displays the great importance of laboratory work
making each teacher, instructor and student to realize that every minute of the laboratory time
need to be effectively utilized to develop these outcomes, rather than doing other mundane
activities. Therefore, for the successful implementation of this outcome-based curriculum, every
practical has been designed to serve as a ‘vehicle’ to develop this industry identified competency
in every student. The practical skills are difficult to develop through ‘chalk and duster’ activity in
the classroom situation. Accordingly, the ‘I’ scheme laboratory manual development team
designed the practical’s to focus on outcomes, rather than the traditional age old practice of
conducting practical’s to ‘verify the theory’ (which may become a byproduct along the way).
This laboratory manual is designed to help all stakeholders, especially the students, teachers and
instructors to develop in the student the pre-determined outcomes. It is expected from each
student that at least a day in advance, they have to thoroughly read the concerned practical
procedure that they will do the next day and understand minimum theoretical background
associated with the practical. Every practical in this manual begins by identifying the
competency, industry relevant skills, course outcomes and practical outcomes which serve as a
key focal point for doing the practical. Students will then become aware about the skills they will
achieve through procedure shown there and necessary precautions to be taken, which will help
them to apply in solving real-world problems in their professional life.
This manual also provides guidelines to teachers and instructors to effectively facilitate student-
centered lab activities through each practical exercise by arranging and managing necessary
resources in order that the students follow the procedures and precautions systematically
ensuring the achievement of outcomes in the students.
Operating systems are an essential part of any computer system. Similarly, a course on operating
systems is an essential part of any computer group. We hope that students will also find it useful.
It provides a clear description of practical performance, execution and working of Operating
System.
The lab manual development team wishes to thank MSBTE who took initiative in the
development of curriculum re-design project and implementation and also acknowledge the
contribution of individual course experts who have been involved in laboratory manual as well as
curriculum development (I scheme) directly or indirectly.
Although all care has been taken to check for mistakes in this laboratory manual, yet it is
impossible to claim perfection especially as this is the first edition. Any such errors and
suggestions for improvement can be brought to our notice and are highly welcome.
Following programme outcomes are expected to be achieved significantly out of the ten
programme outcomes and Computer Engineering and Information Technology programme
specific outcomes through the practicals of the course on Linux Basics.
PO 1. Basic and Discipline specific knowledge: Apply knowledge of basic mathematics,
science and engineering fundamentals and engineering specialization to solve the engineering
problems.
PO 2. Problem analysis: Identify and analyse well-defined engineering problems using codified
standard methods.
PO 3. Design/ development of solutions: Design solutions for well-defined technical problems
and assist with the design of systems components or processes to meet specified needs.
PO 4. Engineering Tools, Experimentation and Testing: Apply modern engineering tools and
appropriate technique to conduct standard tests and measurements.
PO 5. Engineering practices for society, sustainability and environment: Apply appropriate
technology in context of society, sustainability, environment and ethical practices.
PO 6. Project Management: Use engineering management principles individually, as a team
member or a leader to manage projects and effectively communicate about well-defined
engineering activities.
PO 7. Life-long learning: Ability to analyse individual needs and engage in updating in the
context of technological changes.
The following industry relevant skills of the competency “Manage operations of Operating
System” are expected to be developed in you by performing practicals of this laboratory manual.
1. To understand the basics of Linux operating system fundamentals and its open-source nature.
2. Basic Scripting Skills for automating tasks and creating custom shell scripts.
Student shall read the points given below for understanding the theoretical concepts and
practical applications.
1. Students shall listen carefully the lecture given by teacher about importance of subject,
learning structure, course outcomes.
2. Students shall organize the work in the group of two or three members and make a
record of all observations.
3. Students shall understand the purpose of experiment and its practical implementation.
4. Students shall write the answers of the questions during practical.
5. Student should feel free to discuss any difficulty faced during the conduct of practical.
6. Students shall develop knowledge of Operating System fundamental and manipulation
skills as expected by the industries.
7. Student shall attempt to develop related hands on skills and gain confidence.
8. Students shall refer technical magazines; websites related to the scope of the subjects
and update their knowledge and skills.
9. Students shall develop self-learning techniques.
10. Students should develop habit to submit the write-ups on the scheduled dates and time.
Content Page
List of Practicals and Progressive Assessment Sheet
I. Practical Significance: Linux is the base of many of open source operating systems designed
to replace Windows and Mac OS. It is free to download and install on any computer. Because
it is open source, there are a variety of different versions, or distributions, available developed
by different groups. To prevent hacking attempts, many organizations keep their Linux
operating systems private. Many others make their variations of Linux available publicly so the
whole world can benefit at large.
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
VIII. Procedure
Teacher must assign a separate program statement to students. Install and configure Linux ( or
similar) operating system on your computer. Write down the steps for same.
IX. Result(s)
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
XI. References/Suggestions for further reading: include websites/links
1. https://www.tutorialspoint.com/unix/
2. http://www.ee.surrey.ac.uk/Teaching/Unix/
3. https://www.cs.sfu.ca/~ggbaker/reference/unix/
I. Practical Significance: General purpose commands are inbuilt programs that can be invoked in
multiple ways. These commands work interactively from a terminal. A terminal that provides a
command line interface using a shell program.
1.To understand the basics of Linux operating system fundamentals and its open-source nature.
2.Basic Scripting Skills for automating tasks and creating custom shell scripts.
3.Ability to perform file operations and manipulate directories.
2. date: date command is used to display the system date and time. date command is also
Maharashtra State Board of Technical Education (‘K’ scheme) Page 5
LINUX BASICS (312001)
used to set date and time of the system. You must be the super-user (root) to change the
date and time.
Syntax: date [OPTION]... [+FORMAT]
3. echo: echo command in Linux is a built-in command that allows users to display lines of
text or strings that are passed as arguments. It is commonly used in shell scripts and batch
files to output status text to the screen or a file.
Syntax : echo [option] [string]
echo " POLYTECHNIC COLLEGE " output : POLYTECHNIC COLLEGE
4. printf: printf command in Linux is used to display the given string, number or any other
format specifier on the terminal window. It works the same way as “printf” works in
programming languages like C.
Syntax:
$printf [-v var] format [arguments]
printf can have format specifiers, escape sequences or ordinary characters.
Format Specifiers: The most commonly used printf specifiers are %s, %b, %d, %x and
%f.
Examples: %s specifier: It is basically a string specifier for string output.
$printf "%s\n" "Hello, World!"
%d specifier: It is an integer specifier for showing the integral values. $ printf "%d\n"
"213"
5. bc : command is used for command line calculator. It is similar to basic calculator by using
which we can do basic mathematical calculations.
You can use bc command in bash or shell script also for evaluating arithmetic expressions.
Input : $ echo "12+5" | bc Output: 17
Input : $ echo "10^2" | bc Output : 100
6. script :command in Linux is used to make typescript or record all the terminal activities.
After executing the script command it starts recording everything printed on the screen
including the inputs and outputs until exit.
By default, all the terminal information is saved in the file typescript , if no argument is
given.
Syntax: script [options] [file]
If script command is used with filename then all the recorded terminal information is saved
in the given file location.
7. mailx: Linux has an in built Mail User Agent program called mailx. As the name suggests,
it is a console application that is used for sending and receiving emails. The mailx utility
is an enhanced version of the mail command. Along with the functionality provided by the
original mail command, it provides extra features like the ability to send attachments by
using the -a flag. The mailx command is available from a variety of different packages:
bsd-mailx , heirloom-mailx, mailutils
Installing mailx For Ubuntu/Debian: sudo apt-get install bsd-mailx
Sending an Email
Writing the message directly in the command line:
To send a simple email, use the “-s” flag to set the subject in quotes which is followed by
the email of the receiver. After this, mailx waits for the content of the email. To enter new
lines, keep hitting enter. After the content is written, press Ctrl+D.
8. man: The “man” command, short for manual, is a powerful tool in the Linux operating
system that allows users to access detailed information about various commands, utilities,
and system calls.
Syntax : man [option] [command]
For example, to view the manual for the “ls” command, you would enter: man ls
9. clear :clear is a standard Unix computer operating system command that is used to clear
the terminal screen.
Syntax: clear
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
VIII. Program code
1. Write down different options of cal command. (Use $man cal)
IX. Result(s)
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
…………………………………………………………………………………………………………..
.
d. $cal -3
………………………………………………………………………………………
………………………………………………………………………………………
………………………………………………………………………………………
e.$x=echo "var=500;var%=7;var" | bc
$ echo $x
…………………………………..……………………………………………………
f.
g. $ echo "var=10;var++" | bc
……………………………………………………………………………………….
g. printf "%f\n" "20.20"
…………………………………………………………………………………………
………………………….…
(Attach page for output)
2. Give the syntax of commands for displaying the output. (use date)
i. This is …………… Month of the year...........................(Abbreviation for month and
4-digit year)
ii. This is the ..................... ’th day of this year.
(Space for answer)
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
1. https://www.tutorialspoint.com/unix/
2. http://www.ee.surrey.ac.uk/Teaching/Unix/
3. https://www.cs.sfu.ca/~ggbaker/reference/unix/
I. Practical Significance: General purpose commands are inbuilt programs that can be invoked in
multiple ways. These commands work interactively from a terminal. A terminal that provides a
command line interface using a shell program.
2. who : It is used to display who are the users connected to our computer currently
Syntax :who [options] [filename]
Option Description
-a Same as -b -d –login -p -r -t -T -u
-b Time of last system boot
-d Print dead processes
-H Print line of column headings
-l Print system login processes
-m Only hostname and user associated with stdin
-p Print active processes spawned by init
-q All login names and number of users logged on
3. whoami : Display the details of the current working directory
Syntax: whoami [OPTION]
1.--help Option :It gives the help message and exit.
2.--version: Option: It gives the version information and exit.
3. -u option display UID (User ID) This option displays the UID (User ID) instead of the
username.
4. -e This option shows the effective user ID, providing information about the user’s
privileges.
uname [OPTIONs]
1. -a : Displays all available information
2. -s : Shows the kernel name
3. -r : It prints the kernel release date.
6. stty: stty command in Linux is used to change and print terminal line settings. Basically, this
command shows or changes terminal characteristics.
Syntax: stty
7. ps : Display the characteristics of a process. (ie. terminal number,time required, PID no, and
command name)
$ps -f Full listing showing PPID of each process.
$ps -u username Displays processes of user ‘username’
$ps –a Processes of all users
$ps –e Processes including user and system processes.
8. kill : Used to stop execution of particular process by sending aninterrupt signal to the process.
Syntax : kill [signal]PID
$kill 0 Kills all the processes on the terminal except the login shell by special argument ‘0’
$kill 120 230 234 Kills three processes with pid 120 230 234
$kill -9 0 Kills all processes including login shell
$kill -9 $$ Kills login shell
9. sleep : This command pauses the execution for an amount of time which is defined
by NUMBER.
Syntax: sleep NUMBER[SUFFIX]
NUMBER represents the time duration for which the command should sleep.
SUFFIX can be used to specify the unit of time (s for seconds, m for minutes, h for hours, etc.)
Ex. Sleep 30
VIII. Result(s)
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
IX. Practical related questions (Provide space for answers)
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
4. Name the command which terminate the process
5. Write a command for full listing of all running process with output
6. Write use of passwd command.
7. To delay process for specific time command used is ______________ (ps/sleep).
(Space for answer)
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------
X. Exercise:
---------------------------------------------------------------------------------------------
XI. References/Suggestions for further reading: include websites/links
1. https://www.tutorialspoint.com/unix/
2. http://www.ee.surrey.ac.uk/Teaching/Unix/
3. https://www.cs.sfu.ca/~ggbaker/reference/unix/
XII. Assessment Scheme
I. Practical Significance: Data and programs are stored in files. These are organized in
directories. In a simple way, a directory is just a file that contains other files (or directories).
Various operations that can be performed on a file are create, open, read, write, move, close
and rename.
Linux uses a hierarchical structure for organizing files and directories. This structure is
called as a directory tree. The tree has a single root node, the slash character (/), and all
other directories are contained below it. When user first log in to the Unix server, the
specified directory is called as Home directory.
Directory Structure in Unix/Linux:
1. pwd : pwd stands for Present Working Directory. This is most used Linux command to see the
specific Unix Directory on which the user is working on.
Syntax : $pwd
2. cd : The ‘cd’ command is used to change directory. You can use it to change to any directory
by specifying a valid absolute or relative path.
The syntax is as given below
$cd <directory name>
Example: $ cd Directory name
$cd CO2K
$cd .. To come out from current working directory.
Example: $cd ..
$ cd / It changes to root directory.
Example: $ cd /
4. rmdir :It is used to delete/ remove a directory. If the parent directory having subdirectories
then first all subdirectories will be deleted then the parent directory is deleted.
Syntax: $rmdir <directory name>
6. cat: It is used to create the file and displaying the contents of file/files.
Syntax: $ cat >sample (To create a file)
This is sample file in Unix.
<cntrl d>
$ cat sample
where cat is a command and sample is argument. This is sample file in Linax. User can display
contents of more than one file and called as concatenation.
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
2. Create 3 files p1 p2 p3
IX. Result(s)
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------
Practical related questions (Provide space for answers)
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
1. How to shift from Root directory to User (Home) directory?
2. How to see directories?
3. What are different options of ls command? Write down the command along with the
option and note down the output. (Use $man ls command to check options)
4.What are different options of mv command?
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
1.
Exercise:
. Write the command for performing the following tasks sequentially
a. Display your current directory.
b. Create a directory ‘subject’ in the current directory.
1. Create a file ‘sample’ in the directory ‘subject’.
c. Create a file ABCD.txt, create a copy with XXX.txt. Rename the original file with
AACD.txt. Delete the file XXX.txt.
d. Display the inodes of any two files at the same time.
e. Create two files unit1 and unit2 and perform the following operations
1.Copy contents of unit1 to unit2.
2. Display inodes of two files.
3. Rename the file ‘unit1’ to ‘Lesson1’
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
2. http://www.ee.surrey.ac.uk/Teaching/Unix/
3. https://www.cs.sfu.ca/~ggbaker/reference/unix/
I. Practical Significance: Data and programs are stored in files. These are organized in directories.
In a simple way, a directory is just a file that contains other files (or directories). Various
operations that can be performed on a file are create, open, read, write, move, close and rename.
4. file: file 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.
6. cmp: This command is used to compare files when used without options. It uses two filenames
as an argument and display the differences on the terminals.
$cmp filename1 filename2
$cat student1 $cat student2
Harsh Harshu
Sujay Sujay
Smith Smith
$cmp student1 student2
Student1 student2 differ : char 6 line1
7. comm: This command compares two sorted files. It compares each line of first file with its
corresponding line in the second file and generates three column output.
The first column lists the lines only in first file.
The second column lists the lines only in second file. The third column lists the lines in both
files.
Syntax: $comm filename1 filename2
Example:
$cat student1 $cat student2
aa aa
bb pp
cc qq
$comm student1 student2
bb pp aa
cc qq
8. diff :This command is used to show difference between two text files. It also tells which line in
one has to be changed to make the two files identical.
Syntax: $diff filename1 filename2
The options of the result should be like this –
a -Added the text to file
c -Changes are made in the file
d -Deletion operation is performed
< -Lines from the first file
> -Lines from the second file
$cat file1.txt
I need to go to the shop.
I need to buy some mangoes. When I get home, I'll wash the cat.
$cat file2.txt
I need to go to the shop.
I need to buy some mangoes.
Oh yeah, I also need to buy cheese. When I get home, I'll wash the cat.
Use the diff command to compare both files.
$ diff file1.txt file2.txt
The above command should give the result as shown below –
2a3
> Oh yeah, I also need to buy cheese.
From the output, 2a3 means “After line 2 in the first file, a line needs to be added: line 3 from
the second file”.
9. split: It is used to split the large file into smaller files. Default size is 1000 lines per file.
Syntax: $split -n filename tag name
-n number of lines in each smaller file.
-tag name by default the split builds the output files named xaa,xab,xac…..…..
If tag name specified, it replaces the x with that tag name. Example:
Split -10 student
Check it now $ls
xaa xab xac
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
IX. Result(s)
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
X. Practical related questions (Provide space for answers)
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
1. What are options of wc command
2. What is difference between cat pqr and cat pqr|more(file pqr consists of more than 25 lines in
it)
3. What are different options of diff command?
4. What is difference between comm and cmp command
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
Experiment No 06: Execute Linux commands for compressing, decompressing, and archiving files.
I. Practical Significance: Linux file compression commands reduce the size of files and directories
by compressing them, so they are easier to store and transfer. Multiple files and directories can be
grouped and stored as a single archive file with archiving commands.
II. INDUSTRY / EMPLOYER EXPECTED OUTCOME:
1) To understand the basics of Linux operating system fundamentals and its open- source nature.
2) Basic Scripting Skills for automating tasks and creating custom shell scripts.
3) Ability to perform file operations and manipulate directories.
5 Display the name and percentage reduction for each file compressed or
-v decompressed.
6 Decompress a file that was compressed using the gzip command.
-d
This command will create a compressed file of mydoc.txt named as mydoc.txt.gz and delete
the original file.
2. gunzip: gunzip command is used to compress or expand a file or a list of files in Linux. It
accepts all the files having extension as .gz, .z, _z, -gz, -z , .Z, .taz or.tgz and replace the
compressed file with the original file by default. The files after uncompression retain its
actual extension.
Syntax:
gunzip [Option] [archive name/file name]
Example 1: The argument that is passed here is: geeksforgeeks.txt which is a
compressed text file.
Input:
Sc@ubuntu:gunzip abc.txt
Output:
abc.txt.gz
Example 2: The argument that is passed here is: abc.txt.gz which is compressed file
Input:
Sc@ubuntu:gunzip abc.txt.gz
Output:
abc.txt
If a file is compressed using gzip command, a suffix i.e. .gz will be added to the file name
after compression. Hence while uncompressing this file we can either use the original file
name as shown in Example 1 or the filename with the suffix .gz as shown in Example 2 as
an argument.
Example 3: In order to uncompress multiple files using the gunzip command, we can
pass multiple file names as an argument as shown in the below example:
Syntax:
gunzip [file1] [file2] [file3]...
Input:
Sc@ubuntu:gunzip abc.txt.gz gfg.txt
Output:
abc.txt, gfg.txt
3. tar :The Linux ‘tar’ stands for tape archive, which is used to create Archive and extract the
Archive files. tar command in Linux is one of the important commands that provides
archiving functionality in Linux. We can use the Linux tar command to create compressed or
uncompressed Archive files and also maintain and modify them.
Syntax :
tar [options] [archive-file] [file or directory to be archived]
Here ,
tar: The command itself.
[options]: Optional flags or settings that modify the behavior of the tar command.
[archive-file]: The name of the archive file you are creating or working with.
[file or directory to be archived]: The file or directory you want to include in the
archive.
Verifies the integrity of an archive file, ensuring its contents are not
10
-W corrupted.
Updates or adds files or directories to an already existing archive without
11
-r recreating the entire archive.
4. zip: ZIP is a compression and file packaging utility for Unix. Each file is stored in a single
.zip {.zip-filename} file with the extension .zip.
syntax :
zip [file_name.zip] [file_name]
5. unzip:unzip will list, test, or extract files from a ZIP archive, commonly found on Unix
systems. The default behavior (with no options) is to extract into the current directory (and
sub-directories below it) all files from the specified ZIP archive.
Syntax:
unzip [file_name.zip]
Example:
Suppose we have a zip file “name = jayesh_gfg.zip” and we have three text files inside it
“name = a.txt, b.txt and c.txt”. we have to unzip it in the current directory.
Syntax :
unzip jayesh_gfg.zip
VII. Required Resources/apparatus/equipment with specifications
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
VIII. Procedure
IX. Result(s)
………………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
………………..
2. http://www.ee.surrey.ac.uk/Teaching/Unix/
3. https://www.cs.sfu.ca/~ggbaker/reference/unix/
X. Assessment Scheme
1) To understand the basics of Linux operating system fundamentals and its open-source
nature.
2) Basic Scripting Skills for automating tasks and creating custom shell scripts.
3) Ability to perform file operations and manipulate directories.
III. Course Level Learning outcome(s)
CO2 - Execute general purpose commands of the Linux operating system.
1. Ls command: The ls is the list command in Linux. It will show the full list or content of your
directory. Just type ls and press the enter key. The whole content will be shown.
ls -l :it displays various information related to file permission. -l: It stands for long format. It
shows Unix file types, number of hard links, permissions, group, owner, last modified name
and date-time, and size. If the changed date is older than six months, the time is substituted
with the year. A few implementations add extra flags to permissions
Syntax: ls options
Example :ls-l
Ls-ld: Sometimes you don’t want to see the files within the directory; you just want to see just the
permissions on the directory itself. For that you should specify the -d command-line option as well.
With the ls -ld command, you’ll see the permissions on the directory itself, not on its contents.
o ls -ld ~/tmp
o drwxr-x--x 2 lmui 512 Aug 25 17:32 /home/lmui/tmp
This tells you that the directory tmp in my home directory is read/write to myself and read-only for
my group. It cannot be read or written by anyone else; to the directory, since it is executable for all.
The initial d means that it’s a directory.
2. chmod:
Linux chmod command is used to change the access permissions of files and directories. It
stands for change mode.
1. -c, --changes: It is similar to the verbose option, but the difference is that it is reported if a
change has been made.
2. -f, --silent, --quiet: It is used to suppress the error messages.
3. -v, --verbose: It is used to display a diagnostic for every processed file.
4. --no-preserve-root: It is used for not treating the backslash symbol ('/'), especially (the
default).
5. --preserve-root: If this option is used, it will fail to operate recursively on backslash ('/').
6. --reference=RFILE: It is used to specify the RFILE's mode alternatively MODE values.
7. -R, --recursive: It is used to change files and directories recursively.
8. --help: It is used to display the help manual having a brief description of usage and support
options.
9. --version: It is used to display the version information.
3. Chown:
The `chown` command, short for “change owner,” is a powerful tool that allows users to
change the owner of files and directories. This command is particularly useful in
scenarios where administrators need to grant or revoke access to specific resources.
Syntax of chown Command in Linux
The chown command in Linux has the following syntax:
Syntax: chown [options] new_owner[:new_group] file(s)
4. Chgrp:
The `chgrp` command in Linux is used to change the group ownership of a file or directory.
Syntax of `chgrp` command in Linux
chgrp [OPTION]… GROUP FILE…
chgrp [OPTION]… –reference=RFILE FILE…
Here the group name of the file abc.txt was changed from kcVirtual to geeksforgeeks. Note
that when files are created the groupname of the file is the same as the owner under which
the file was created.
VII. Required Resources/apparatus/equipment with specifications
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
IX. Result(s)
………………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
…………………………………………………………………………………………………
1.explain the differences and uses of chmod, chown and chgrp commands in Linux?
2.what is meant by ownership permissions and how they function in an operating system?
3. How would you manage permissions in a distributed file system?
4. Explisn how to change file/directory permission using shorthand notations?
https://www.computerhope.com/unix/uchmod.htm
https://www.geeksforgeeks.org/
The following table lists out the basic commands to use the vi editor –
Sr.NO Command Description
1 vi filename Creates a new file if it already does not exist, otherwise opens an
existing file.
Following is an example to create a new file test1 if it already does not exist in the current working
directory − The above command will generate the following output
$vi test1
~
~
~
~
~
~
~
~
~
~
~
"test1" [New File]
You will notice a tilde (~) on each line following the cursor. A tilde represents an unused line. If
a line does not begin with a tilde and appears to be blank, there is a space, tab, newline, or some
other non-viewable character present.
Operation Modes
While working with the vi editor, we usually come across the following two modes –
Command mode − This mode enables you to perform administrative tasks such as saving the
files, executing the commands, moving the cursor, cutting (yanking) and pasting the lines or
words, as well as finding and replacing. In this mode, whatever you type is interpreted as a
command.
Insert mode – This mode enables you to insert text into the file. Everything that's typed in
Operating System (22516) Maharashtra State Board of Technical Education 58 this mode is
interpreted as input and placed in the file. vi always starts in the command mode. To enter text,
you must be in the insert mode for which simply type i. To come out of the insert mode, press
the Esc key, which will take you back to the command mode.
Control Commands:
Editing Files
To edit the file, you need to be in the insert mode. There are many ways to enter the insert mode
from the command mode –
5 o Creates a new line for text entry below the cursor location
6 O Creates a new line for text entry above the cursor location
Deleting Characters:
Here is a list of important commands, which can be used to delete characters and
lines in anopen file −
4 d^ Deletes from the current cursor position to the beginning of the line
5 d$ Deletes from the current cursor position to the end of the line
6 D Deletes from the cursor position to the end of the current line
Change Commands
You also have the capability to change characters, words, or lines in vi without deleting them.
3 r Replaces the character under the cursor. vi returns to the command modeafter
the replacement is entered.
5 s Replaces the current character with the character you type. Afterward, you
are left in the insert mode.
6 S Deletes the line the cursor is on and replaces it with the new text. Afterthe
new text is entered, vi remains in the insert mode.
2 yw- Copies the current word from the character the lowercase w cursor is on,
until the end of the word.
Ex mode command
Press Esc key and then (:) colon to enter ex-mode commands. A colon is displayed at
the lefthand corner of the last line on your screen.
Command Action
:w Saves file and remains in editing mode
Advanced Commands:
There are some advanced commands that simplify day-to-day editing and allow for more
efficient use of vi −
6 < This is put in an expression escaped with the backslash to find the ending or
the beginning of a word.
Running Commands:
The vi has the capability to run commands from within the editor. To run a command,
you only need to go to the command mode and type :! command. For example, if you
want to check whether a file exists before you try to save your file with that filename,
you can type :! ls and you will see the output of ls on the screen. You can press any key
(or the command's escape sequence) to return to your vi session.
Replacing Text:
The substitution command (:s/) enables you to quickly replace words or groups of words
withinyour files. Following is the syntax to replace text –
:s/search/replace/g
The g stands for globally. The result of this command is that all occurrences on the
cursor's lineare changed.
VII. Required Resources/apparatus/equipment with specifications
Sr. No. Equipment Name with Broad Specifications Relevant LLO Number
1 Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM),
internal hard disk drives, Mouse, Keyboard, and opensource
operating System. (RedHat, Ubuntu etc.).
VIII. Procedure
IX. Result(s)
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
X. Practical related questions (Provide space for answers)
1. What is the difference between Type o and Type O?
2. State the three ways quit the vi-editor.
3. What is effect of (Type this at colon mode and observe the changes in your file)
a. set nu
b. set ic
c. set nonu
d. set noai
4. Give vi command to delete line to the left of cursor.
5. What is difference between yank and delete?
6. What are different modes in Vi editor?
7. Observe the output of following commands:
i) at colon mode
:abbr MSBTE Maharashtra State Board Of Technical
Education Now in the beginning of your file type MSBTE
and press space barWrite down the output
……………………………………………………………………………………
ii) Go to beginning of your file press
4YY Then move to end of your file
and press ‘P’
Write the purpose of the command
(Space for answer)
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
….........................................................................................................................................................
.
……………………………………………………………………………………………………….
……………………………………………………………………………………………………….
……………………………………………………………………………………………………………
When you are searching for files in UNIX, DOS, or Windows, or on the web, you can simplify
your search by using a wildcard. Wildcards may also simplify commands issued from the
command line in UNIX or DOS.
II. INDUSTRY / EMPLOYER EXPECTED OUTCOME:
1) To understand the basics of Linux operating system fundamentals and its open-source
nature.
2) Basic Scripting Skills for automating tasks and creating custom shell scripts.
3) Ability to perform file operations and manipulate directories.
Use wildcard characters (e.g., *, ?, []) to list and manipulate specific sets of files within the
directory.
V. Relevant Affective Domain related outcome(s)
1. Follow precautionary measures.
2. Follow installation steps.
3. Follow ethical practices.
Since the Linux system uses filename so much it provides us with special characters to help us
rapidly specify groups of filenames. These special characters are called wildcards.
Sr. Wildcard Meaning
NO
* Matches any character
? Matches any single character
[] Matches any character that is a member of the set character
In the above example, we first use the ls command to list the directory content and then since we
only wanted the files that end with .txt we used wildcard * and created the command ls *.txt
ls *.txt where
* matches any character and
*.txt means any file that ends with .txt.
2. List all the .txt files that begin with "textFile" and have exactly 1 character after that. For
example textFile9.txt
In the above example, we first listed all the text files in the directory using ls *.txt and then we
used wildcard ? and created command ls textFile?.txt to filter the results as per our requirement
ls textFile?.txt
where
3. What if we wanted to get only the files and folders that have numbers 2, 4, or 6.
So the file can start with any character and end with any character but it should contain at least one
of the three numbers
In the above example, we used the wildcard [] and created a command ls *[2,4,6]* to get the
desired results.
ls *[2,4,6]* where
* represents any character
[2,4,6] represent that the file and folders with either number 2 or 4 or 6
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
VIII. Procedure
Exlain all wild card characters.
Note: Write terminal output in Result Section
IX. Result(s)
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
https://www.geeksforgeeks.org/
https://stackoverflow.com/
Pipes are a powerful and essential concept in the Linux command-line environment. They allow
you to connect the output of one command as the input to another, enabling you to create
complex and efficient data processing workflows.
II. INDUSTRY / EMPLOYER EXPECTED OUTCOME:
1) To understand the basics of Linux operating system fundamentals and its open-source
nature.
2) Basic Scripting Skills for automating tasks and creating custom shell scripts.
3) Ability to perform file operations and manipulate directories.
Creating a text file in the terminal is a straightforward process that requires minimal
effort. It works efficiently when creating a single text file promptly. However, when the
need arises to create multiple text files simultaneously, the process can become tedious.
The command involves using the standard redirect symbol (>) followed by a spacebar
and the desired file name.
Syntax:> filename.txt
If you want to create several text files at once, then you can add the redirect symbol after
the previous filename and chain the command repeatedly to create multiple empty files.
Syntax:> file.txt > file2.txt > file3.txt
The above command creates three empty text files. The redirect symbol is quite time-
saving if you just want to create a single text file. It gets quite longer than the touch
command to create multiple empty text files.
3) CAT Command
This method is incredibly simple and user-friendly. To create a new text file using this
method, all you need to do is type “CAT” followed by two redirect symbols (>>) and the
desired file name. While it is not necessary to use the >> symbols, you can also use a
single > symbol. However, caution must be exercised when using a single > symbol, as it
can inadvertently overwrite the existing content in the text file if the file already exists.
This method combines the functionality of the touch and redirect symbol commands. It is
a unique approach, best suited for creating empty, never-edited files. If you prefer to
create and type directly into the text file, this method is highly efficient. It eliminates the
need to open a separate editor, saving you time and offering a straightforward command.
The below command creates an empty yet edited file as it prompts the user to create a
text file and type in the file at the same time. So, if you do not want to edit the file,
simply press CTRL+C and it will simply exit and create an empty file.
Similar to the echo command, we have the printf command as well. The print command
does the same thing as the echo command but in a C style rather than shell-style editing.
printf "" >> filename.txt
printf "" >> file1.txt >> file2.txt >> file3.txt
printf “This is some text here \n The second line \n The third line” >> file.txt
The print command does some pretty C-like things, such as the newline character and the
variable names can be used as well, but that is not for a simple text file. But still, the
printf command can be useful in a lot of cases to edit files on the go.
b) Create a complex pipeline by chaining multiple commands together using pipes (|).
Example:
Cat logfile.txt|grep”error”|sort|uniq-c|awk ’{print $2,$1}’>error_count.txt
1. Reads the content of "logfile.txt" using cat.
2. Filters lines containing "error" using grep.
3. Sorts the filtered lines using sort.
4. Removes duplicate consecutive lines and counts occurrences with uniq -c.
5. Uses awk to rearrange the columns and redirect the output to "error_count.txt".
VII. Required Resources/apparatus/equipment with specifications
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
VIII. Procedure
Create a text file and performallcommands.
Note: Write terminal output in Result Section
IX. Result(s)
……………………………………………………………………………………………………
……………………………………………………………………………………………………
…………………………………………………………
X. Practical related questions (Provide space for answers)
1. Count the number of lines in a file
2. Search for a specific pattern in a file
3. Sort the lines of a file
4. Combine multiple commands
……………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
…………………………………………………….
XI. References/Suggestions for further reading:
https://www.geeksforgeeks.org/
https://stackoverflow.com/
Assessment Scheme
Performance indicators Weitage
Process related(10 Marks) 30%
1. Logic Formation 10%
2. Debugging Ability 15%
3. Follow ethical practice 5%
Product related (15 Marks) 70%
4. Interactive GUI 20%
5. Answer to Practical related questions 20%
6. Expected Output 20%
7. Timely Submission 10%
Total(25 Marks) 100%
1) Input Redirection
Just as the output of a command can be redirected to a file, so can the input of a command be
redirected from a file. As the greater-than character > is used for output redirection, the less-
than character < is used to redirect the input of a command.
The commands that normally take their input from the standard input can have their input
redirected from a file in this manner. For example, to count the number of lines in the
file users generated above, you can execute the command as follows −
$ wc -l users
2 users
$
Upon execution, you will receive the following output. You can count the number of lines in the
file by redirecting the standard input of the wc command from the file users −
$ wc -l < users
Maharashtra State Board of Technical Education (‘K’ scheme) Page 62
LINUX BASICS (312001)
Note that there is a difference in the output produced by the two forms of the wc command. In the first
case, the name of the file users is listed with the line count; in the second case, it is not.
In the first case, wc knows that it is reading its input from the file users. In the second case, it only
knows that it is reading its input from standard input so it does not display file name.
2) Output Redirection
The output from a command normally intended for standard output can be easily diverted to a file
instead. This capability is known as output redirection.
If the notation > file is appended to any command that normally writes its output to standard output,
the output of that command will be written to file instead of your terminal.
Check the following who command which redirects the complete output of the command in the users
file.
$ cat users
$
If a command has its output redirected to a file and the file already contains some data, that data will
be lost. Consider the following example −
line 1
$
You can use >> operator to append the output in an existing file as follows −
$ cat users
line 1
line 2
$
VII. Required Resources/apparatus/equipment with specifications
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
VIII. Procedure
IX. Result(s)
………………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
…………………….
X. Practical related questions (Provide space for answers)
1) What is input redirection in Linux
2) How can you redirect both standard output and standard error to a file in Linux
3) What is the purpose of the >> operator in Linux output redirection?
…………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
Maharashtra State Board of Technical Education (‘K’ scheme) Page 64
LINUX BASICS (312001)
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
…………………................................
I. Practical Significance: A filter is a program that takes a flow of data from the standard input,
processes or filters it and send the result to standard output.
3. tail : It is a used to print last few numbers of lines (10 lines by default) of a certain file, then
terminates.
Syntax:
$tail {[+/-]n [lbc]}filename
Options Meaning
+n Displays all lines starting from nth line.
-n Displays n lines from end of the file
l Indicates Lines
b Indicates blocks
c Indicates characters
Example:
$tail -20l student
Displays last 20 lines of student file.
$tail +20l student
Displays all lines starting from 20th line of the student file.
4. cut: It is used to copy the specified columns to the standard output file. It is used to cut portion of a
file. It takes filenames as command line arguments or input from standard input. It does not delete
the selected portion of a file.
Syntax: $cut [-f/-c] [n1,n2] filename
Where n1,n2 are the field/character number.
-f Displays specified field. Also uses -d for field separator.
-c Displays specified column character by character. Example 1:
$cat student1
Ajay 1990 50
Vijay 1992 60
Sujit 1991 70
$cut -f1,2 student1
Ajay 1990
Vijay 1992
Sujit 1991
In this output it will display 1st and 2nd fields values
Example 2:
Maharashtra State Board of Technical Education (‘K’ scheme) Page 68
LINUX BASICS (312001)
5. Paste :It is used to join files horizontally (parallel merging) by outputting lines consisting of lines
from each file specified, separated by tab as delimiter, to the standard output. When no file is
specified, or put dash (“-“) instead of file name, paste reads from standard input and gives output
as it is until a interrupt command [Ctrl-c] is given.
Syntax:
paste [OPTION]... [FILES]...
Create files for demonstration:
$cat stdname
Ajay
Vijay
Sujit
$cat birthyear
1980
2001
1996
$paste stdname birthyaer
Ajay 1980
Vijay 2001
Sujit 1996
contents are ASCII. Using options in sort command, it can also be used to sort numerically.
When we have a mix file with both uppercase and lowercase letters then first the lower case letters
would be sorted following with the upper case letters .
Option Meaning
-o write the output to a new file
-n sort a file numerically
-r Sort in Reverse Order
Example:
7. uniq: uniq command in Linux is a command-line utility that reports or filters out the repeated lines
in a file.
Syntax:uniq [OPTION]... [INPUT [OUTPUT]]
Options Meaning
-c Precedes each output line with a count of the number of times each line appeared in the
input file.
-d Displays only the repeated lines.
-u Displays only the unrepeated lines
Example :
$cat kt.txt
I love music.
I love music.
I love music.
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
VIII. Program code
3. Create a text file with ten lines of text in it.
4. Print first 5 lines of file (use head command)
5. Print last 4 lines of file(use tail command)
IX. Result(s)
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
X. Practical related questions (Provide space for answers)
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
1. How many lines will be displayed with head command if number is not specified.
2. What are different types of filters used in Linux?
3. Give applications of paste Command.
(Space for answer)
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------
XI. Exercise:
4. Create file with following contents
$ cat file2
Chhatrapati Shahu Maharaj
Dr.B.R.Ambedkar
Budhha
Dr.B.R.Ambedkar
Budhha
Dr.B.R.Ambedkar
Budhha
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
1) To understand the basics of Linux operating system fundamentals and its open-source nature.
2) Basic Scripting Skills for automating tasks and creating custom shell scripts.
3) Ability to perform file operations and manipulate directories.
$cat OS
Unix
Linux
Ubuntu
$grep -n Unix OS
It searches Unix pattern and displays line number where that pattern matched.
Options:
$ grep –c <pattern> <files>: This prints total number of lines that match the pattern in given files.
$ grep –n <pattern> <files>: This prints line that matches pattern along with its line number.
$ grep –v <pattern> <files>: This inverts the sense of matching. It will show the lines which do
not contain given pattern.
2) egrep: The egrep command in Linux is a powerful tool used for searching and manipulating text
based on patterns. It stands for 'Extended Global Regular Expressions Print', and as the name
implies, it extends the capabilities of the original grep command by supporting additional regular
expression syntax. It is commonly used for searching through text files and filtering output from
other commands.
Syntax :egrep [options] 'pattern' [file...]
options: This is where you specify any flags or options that change how the egrep command
behaves.
pattern: This is the regular expression that egrep will search for. It must be enclosed in quotes.
file: This is the file(s) in which egrep will search for the pattern. If no file is specified, egrep reads
from the standard input.
Example:
3) sed :command in UNIX stands for stream editor and it can perform lots of functions on file like
searching, find and replace, insertion or deletion. Though most common use of SED command in
UNIX is for substitution or for find and replace. By using SED you can edit files even without
opening them, which is much quicker way to find and replace something in file, than first opening
that file in VI Editor and then changing it.
SED command in unix supports regular expression which allows it perform complex pattern
matching.
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
VIII. Program code
6. Create a text file with ten lines of text in it.
7. Use grep , egrep and sed commands on above file.
IX. Result(s)
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
X. Practical related questions (Provide space for answers)
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
1. Give use of grep command.
2. Explain different options of grep command.
3. Compare grep and egrep command.
(Space for answer)
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
XI. Exercise:
2) Replace the first instance of a pattern ‘abc’ with another pattern ‘def’ using sed command
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
A shell script is a computer program designed to be run by the Unix/Linux shell which could
be one of the following
The Bourne Shell
The C Shell
The Korn Shell
The GNU Bourne-Again Shell
A shell is a command-line interpreter and typical operations performed by shell scripts
include file manipulation, program execution, and printing text.
II. INDUSTRY / EMPLOYER EXPECTED OUTCOME:
1) To understand the basics of Linux operating system fundamentals and its open-source nature.
2) Basic Scripting Skills for automating tasks and creating custom shell scripts.
3) Ability to perform file operations and manipulate directories.
Read user input, exit and exit status commands, expr, and logical operators in shell scripts.
V. Relevant Affective Domain related outcome(s)
1. Follow precautionary measures.
2. Follow naming conventions.
3. Follow ethical practices
VI. Relevant Theoretical Background (with diagrams if required)
Syntax
read <variable_name>
2) exit and exit status commands
The exit command terminates a script, just as in a C program. It can also return a value,
which is available to the script's parent process.
Every command returns an exit status (sometimes referred to as a return status or exit
code). A successful command returns a 0, while an unsuccessful one returns a non-
zero value that usually can be interpreted as an error code.
3) Expr command
The expr command in Unix evaluates a given expression and displays its corresponding
output. It is used for:
Basic operations like addition, subtraction, multiplication, division, and modulus on integers.
Evaluating regular expressions, string operations like substring, length of strings etc.
Syntax:
$expr expression
4) logical operators
They are also known as boolean operators. These are used to perform logical operations.
They are of 3 types:
Logical AND (&&): This is a binary operator, which returns true if both the operands are
true otherwise returns false.
Logical OR (||): This is a binary operator, which returns true is either of the operand is true
or both the operands are true and return false if none of then is false.
Not Equal to (!): This is a unary operator which returns true if the operand is false and
returns false if the operand is true.
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
VIII. Procedure: Teacher must assign a separate statements to students
IX. Result(s)
………………………………………………………………………………………………………
……………………………………………………………………………………………………
…………………………………………………………………………………………………
References/Suggestions for further reading:
Maharashtra State Board of Technical Education (‘K’ scheme) Page 81
LINUX BASICS (312001)
https://www.computerhope.com/unix/uchmod.htm
https://www.geeksforgeeks.org/
Assessment Scheme
Performance indicators Weitage
Process related(10 Marks) 30%
1. Logic Formation 10%
2. Debugging Ability 15%
3. Follow ethical practice 5%
Product related (15 Marks) 70%
4. Interactive GUI 20%
5. Answer to Practical related questions 20%
6. Expected Output 20%
7. Timely Submission 10%
Total(25 Marks) 100%
List of student Team Members
1…………………………………
2………………………………....
3…………………………………
Marks Obtained Dated signature of
Teacher
Process Related(10) Product Related(15) Total(25)
I. Practical Significance: If is a statement that allows the programmer to make a decision in the
program based on conditions he specified. If the condition is met, the program will execute certain
lines of code otherwise, the program will execute other tasks the programmer specified.
The if...else...fi statement is the control statement that allows Shell to execute statements in a
controlled way and make the right choice.
Syntax;
if [ expression ] ; then
Statement(s) to be executed if expression is true
else
Statement(s) to be executed if expression is not true
fi
The Shell expression is evaluated in the above syntax. If the resulting value is true, given
statement(s) are executed. If the expression is false, then no statement will be executed.
Relational operators are used along with if statement.
Relational operators used by if
Operator Meaning
-eq Equal to
-ne Not equal
-gt Greater than
-ge Greater than or equal to
-lt Less than
-le Less than or equal to
General Syntax
1.Single Decision: -
Syntax:-
if [ condition ]; then
### series of code goes here
fi
e.g.
if [ "$X" -lt "0" ]; then
echo "X is less than zero"
fi
2.Double Decision: -
Syntax:-
if [ condition ]; then
Statements if the condition is satisfied
else
Statements of code if the condition is not satisfied
fi
3.Multiple if condition: -
Syntax:-
if [ condition1 ]; then
Statements for condition1
elif [ condition2 ]; then
Statements for condition2
else
Statements if the condition is not satisfied
fi
4.Double –bracket:-
Syntax:-
if ((condition)) then
Statements goes here
fi
To type any program in Linux you need the compiler. vi editor is used for creating file in
Linux.
Example :
Write a shell script to display welcome message with today’s date in it.
In vi editor write a program code and save and quit with filename ‘sample.sh’.
$vi sample.sh
(Now press escape and i to change the input mode and type following program)
#sample.sh
#use of if-then statement
if whoami; then
var1=`whoami`
echo “Welcome $var1”
fi
if date; then
echo “It displays todays date”
fi
echo “This is end of script”
“Welcome User1”
Mon Feb 5 22:29:29 PST 2023
“It displays todays date”
“This is end of script”
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
VIII. Program code
1. Execute shell script by considering example like giving passing grades to students using if
statement:
1. Single Decision.
2.Double Decision.
3.Multiple if statements.
Note: Attach the code at the end.
IX. Result(s)
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
X. Practical related questions (Provide space for answers)
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
1. https://www.tutorialspoint.com/unix
2. http://www.ee.surrey.ac.uk/Teaching/Unix/
3. https://www.cs.sfu.ca/~ggbaker/reference/unix/
4. https://www.shellscript.sh/test.html
XIII. Assessment Scheme
Performance indicators Weitage
Process related(10 Marks) 30%
1. Logic Formation 10%
2. Debugging Ability 15%
3. Follow ethical practice 5%
Product related (15 Marks) 70%
4. Interactive GUI 20%
5. Answer to Practical related questions 20%
6. Expected Output 20%
7. Timely Submission 10%
Total(25 Marks) 100%
List of student Team Members
1…………………………………
2………………………………....
3…………………………………
Experiment No 16: . Execute the shell script by using the while statement.
I. Practical Significance: The while loop enables you to execute a set of commands repeatedly until
some condition occurs. It is usually used when you need to manipulate the value of a variable
repeatedly.
1) To understand the basics of Linux operating system fundamentals and its open-source nature.
2) Basic Scripting Skills for automating tasks and creating custom shell scripts.
3) Ability to perform file operations and manipulate directories.
A while loop is a control flow statement in Bash scripting that allows a certain block of code to be
executed repeatedly as long as a specified condition is true. The loop provides a way to automate
repetitive tasks and is a fundamental construct in scripting and programming.
Syntax:
while [condition]; do
..
..
..
done
Example:
a=1
Maharashtra State Board of Technical Education (‘K’ scheme) Page 89
LINUX BASICS (312001)
while [ $a -le 5 ]; do
echo “value of a=” $a
a=`expr $a + 1`
done
1.The break statements: The break statement is used to terminate the execution of the entire loop,
after completing the execution of all of the lines of code up to the break statement using break
keyword.
2.The continue statement: The continue statement is similar to the break command, except that it
causes the current iteration of the loop to exit, rather than the entire loop.
Example:
$cat fact.sh
echo "Enter a number"
read num
fact=1
while [ $num -gt 1 ];
do
fact=$((fact * num))
num=$((num - 1))
done
echo “factorial of a number is $fact”
Relevant LLO
Sr.No Equipment Name with Broad Specifications
Number
Computer system with all necessary components like; motherboard,
random access memory (RAM), read-only memory (ROM), internal hard
1 All
disk drives, Mouse, Keyboard, and open source operating System.
(RedHat, Ubuntu etc.).
VIII. Program code
IX. Result(s)
--------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
X. Practical related questions (Provide space for answers)
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
4. Write a shell script to accept five digit number and perform addition of all
digits.
5. Write script for printing even numbers between 1 to 20.
5. https://www.tutorialspoint.com/unix
6. http://www.ee.surrey.ac.uk/Teaching/Unix/
7. https://www.cs.sfu.ca/~ggbaker/reference/unix/
8. https://www.shellscript.sh/test.html
XII. Assessment Scheme
Performance indicators Weitage
Process related(10 Marks) 30%
1. Logic Formation 10%
2. Debugging Ability 15%
3. Follow ethical practice 5%
Product related (15 Marks) 70%
4. Interactive GUI 20%
5. Answer to Practical related questions 20%
6. Expected Output 20%
7. Timely Submission 10%
Total(25 Marks) 100%
List of student Team Members
1…………………………………
2………………………………....
3…………………………………
4…………………………………
Experiment No 17: . Execute the shell script by using the for statement.
I. Practical Significance: The for loops iterate through a set of values until the list is exhausted. In
simple terms the for loop operates on lists of items. It repeats a set of commands for every item in
a list.
1) To understand the basics of Linux operating system fundamentals and its open-source
nature.
2) Basic Scripting Skills for automating tasks and creating custom shell scripts.
3) Ability to perform file operations and manipulate directories.
echo $var
done
IX. Result(s)
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
X. Practical related questions (Provide space for answers)
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
1. Execute shell script for printing table of given number using FOR loop
2. Write a shell script to print pattern
1
2 2
3 3 3
4 4 4 4
NUMBERS="1 2 3 4 5 6 7"
for NUM in $NUMS do
Q=`expr $NUM % 2`
if [ $Q -eq 0 ];
then
echo "Number is an even number!!" continue
fi
echo "Found odd number"
done
-----------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
1. https://www.tutorialspoint.com/unix
2. http://www.ee.surrey.ac.uk/Teaching/Unix/
3. https://www.cs.sfu.ca/~ggbaker/reference/unix/
4. https://www.cyberciti.biz/faq/bash-for-loop/
5. https://bash.cyberciti.biz/guide/For_loop