0% found this document useful (0 votes)
18 views

Sa Jochu

Uploaded by

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

Sa Jochu

Uploaded by

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

GOVT.

WOMEN’S
POLYTECHNIC COLLEGE
KALAMASSERY

LABORATORY RECORD

NAME: JYOLSNA E.B

BRANCH: COMPUTER ENGINEERING

REG NO: 2201132207

YEAR: 2024

1|Page
GOVT. WOMEN’S
POLYTECHNIC COLLEGE
KALAMASSERY

LABORATORY RECORD

NAME: JYOLSNA E.B

BRANCH: COMPUTER ENGINEERING

REG NO: 2201132207

YEAR: 2024

CERTIFICATE

Certified that this is the bonafide record of work done

In System Administration Laboratory by Sri Jyolsna E.B during the year 2024

Internal Examiner Staff-in-Charge

External Examiner Head of Section

2|Page
INDEX
Sl DATE PAGE INITIAL
No: No : OF
NAME OF EXPERIMENT TEACHE
R
01 FAMILIARIZATION OF LINUX OS, FILES AND 22-08-2024 04
DIRECTORY ORGANIZATION
02. SYSTEM MANAGEMENT COMMANDS 22-08-2024 07

03. USER AND GROUP MANAGEMENT COMMANDS 9-09-2024 10

04. FILE AND DIRECTORY MANAGEMENT COMMANDS 4-09-2024 13

05. INPUT AND OUTPUT REDIRECTIONS ON LINUX 4-09-2024 17

06. PIPES AND FILTERS 8-10-2024 20

07. PROCESS MANAGEMENT COMMANDS 8-10-2024 34

08. BACK UP AND RECOVERY MANAGEMENT 9-09-2024 38

09. FAMILIARIZATION OF SHELL AND TYPES OF SHELLS 9-09-2024 41


USED IN LINUX OS DATE:

10. SHELL SCRIPTING 8-10-2024 45

3|Page
Experiment No : 01 Date : 22-08-2024

FAMILIARIZATION OF LINUX OS,FILES AND DIRECTORY


ORGANIZATION
AIM:
To familiarize the structure of Linux Operating System, file and directory
organization.
THEORY
LINUX OPERATING SYSTEM
An operating system can be described as an interface among the computer hardware
and the user of any computer. It is a group of software that handles the resources of
the computer hardware and facilitates basic services for computer programs. The
primary aim of an operating system is to provide a platform where a user can run any
program conveniently or efficiently. Linux OS is one of the famous versions of the
UNIX OS. It is developed to provide a low-cost or free OS for several personal
computer system users.
ARCHITECTURE OF LINUX SYSTEM
COMPONENTS OF LINUX OS
1. Kernel
The kernel is one of the core section of an operating system. The kernel facilitates
required abstraction for hiding details of low-level hardware or application programs
to the system.
Types
o Monolithic Kernel
o Micro kernels
o Exo kernels
o Hybrid kernels
2. System Library
These libraries can be specified as some special functions. These are applied for
implementing the operating system's functionality and don't need code access rights of
the modules of kernel.

4|Page
3. Hardware layer
Linux operating system contains a hardware layer that consists of several peripheral
devices like CPU, HDD, and RAM.
4. System Utility Programs
It is responsible for doing specialized level and individual activities.
5. Shell
It is an interface among the kernel and user. It can take commands through the user
and runs the functions of the kernel. The shell is available in distinct types of OSes.
These operating systems are categorized into two different types, which are the
graphical shells and command-line shells. The graphical line shells facilitate the
graphical user interface, while the command line shells facilitate the command line
interface.
Types of Shells
o Korn shell
o Bourne shell
o C shell
o POSIX shell
FEATURES
o Portable
o Open source
o Multiprogramming
o Multi-user
o Hierarchical file system
o Security
o Shell
APPLICATIONS
Thousands of governments and companies are using Linux operating system across
the world because of lower money, time, licensing fee, and affordability. Linux can be
used within several types of electronic devices. These electronic devices are easily
available for users worldwide.

5|Page
A few of the famous Linux-based electronic devices are :Yamaha Motive Keyboard,
Volvo In-Car Navigation System, TiVo Digital Video Recorder, Sony Reader, Sony
Bravia Television, One Laptop Per child XO2,Motorola MotoRokr EM35 phone,
Lenovo IdeaPad S9,HP Mini 1000,Google Android Dev Phone 1,Garmin Nuvi 860,
880, and 5000,Dell Inspiron Mini 9 and 12.
LINUX FILE SYSTEM AND DIRECTORY
A file system is a method for storing and organizing data on a computer. It is
responsible for managing data stored on disk and other storage devices. The Linux file
system is designed to provide a hierarchical and organized structure for files and
directories, making it easy to navigate and manage data on the system.
One of the primary functions of directories in Linux is to provide a hierarchical
structure for organizing files The Linux file system structure is a complex hierarchy
that includes multiple layers, each with its own role in managing and organizing data
on storage devices. At the top of the hierarchy is the root directory (/), which contains
all other directories and files. Below the root directory are several subdirectories, each
with its own purpose and set of files. With the help of this hierarchical structure,
complicated systems can be structured logically and organized. This makes it simpler
to locate and handle files on the system.

RESULT
Familiarized with Linux Operating System, Files and Directories.

6|Page
Experiment No : 02 Date : 22-08-2024

SYSTEM MANAGEMENT COMMANDS

AIM :
To familiarize with the management of system using Linux commands - date, time,
pwd, ps, who, whoami, uptime, users, groups.

PROCEDURE:
1. Write command to display Current Date and Time in Linux
Command: $date
2. Write command to display Time in GMT
Command: $date -u
3. Write command to display the Given Date String in the Format of Date
Command: $date -d "2023-12-31"
4. Write command to display Past Dates
Command:$date --date="5 days ago"
5. Write command to display Future Dates
Command: $date --date="10 days"
6. Write command to set the System Date and Time
Command: $sudo date -s "2024-10-05 12:00:00"
7. Write command to use of Format specifiers with date command
Command: $date +"%Y-%m-%d %H:%M:%S"
8. Write command to print the current working directory in Linux
Command: $pwd
9. Write command to redirect the output of ‘pwd’ to a file in Linux?
Command: $pwd > filename.txt
10. Write command to shows the processes for the current shell.
Command: $ps

7|Page
11. Write command to view all running processes.
Command: $ps -A
12. Write command to show list of users logged in to system
Command: $who -u
13. Write command to show time of the system when it booted last time
Command: $who -b -H

8|Page
OUTPUT

1. Sat Oct 5 12:34:45 IST 2024

2. Sat Oct 5 07:04:45 UTC 2024

3. Sun Dec 31 00:00:00 IST 2023

4. Mon Sep 30 12:34:45 IST 2024

5. Tue Oct 15 12:34:45 IST 2024

6. Sat Oct 5 12:00:00 IST 2024

7. 2024-10-05 12:34:45
8. /home/user

9. PID TTY TIME CMD


1234 pts/0 00:00:00 bash
5678 pts/0 00:00:00 ps
10. PID TTY TIME CMD
1 ? 00:00:10 systemd
2 ? 00:00:00 kthreadd
... (many more processes)
11. user1 pts/0 2024-10-05 12:00 . 1234

12. user2 pts/1 2024-10-05 11:30 . 5678

13. system boot 2024-10-04 09:00

RESULT
The above commands are executed successfully and obtained desired output.

9|Page
Experiment No : 03 Date : 9-09-2024
USER AND GROUP MANAGEMENT COMMANDS
AIM:
To familiarize with the management of user and groups using Linux commands like
useradd, passwd, usermod, userdel, groupadd, groupmod, groupdel, and gpasswd.

PROCEDURE:

1. Write command to add a new user to the system.


Command: $sudo adduser username
2. Write command to assign a password to a new user.
Command: $sudo passwd username
3. Write command to change the user ID of a user.
Command: $sudo usermod -u new_user_id username
4. Write command to change the user login name of the user.
Command: $sudo usermod -l new_login_name old_login_name
5. Write command to list down all the system users.
Command: $cat /etc/passwd or compgen -u
6. Write command to create a new group called "newgroup".
Command: $sudo groupadd newgroup
7. Write command to create a new group with specific group ID.
Command: $sudo groupadd -g groupid newgroup
8. Write command to change the group "newgroup" to "oldgroup".
Command: $sudo groupmod -n oldgroup newgroup
9. Write command to assign a password to a new group.
Command: $sudo gpasswd newgroup
10. Write command to add a user to an existing group.
Command: $sudo usermod -aG groupname username
11. Write command to delete a user from a group.
Command: $sudo gpasswd -d username groupname
12. Write command to delete a new user you created.
Command: $sudo deluser username

10 | P a g e
OUTPUT:

1. Adding user username' ...


Adding new group username' (1001) ...
Adding new user username' (1001) with group username' ...
Creating home directory /home/username' ... Copying files from /etc/skel' ...
Enter new password:
Retype new password:
passwd: password updated successfully
Changing the user information for username
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y

2. Enter new password:


Retype new password:
passwd: password updated successfully

3. No output unless there is an error

4. No output unless there is an error

5. root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
...
username:x:1001:1001:,,,:/home/username:/bin/bash
Output for compgen -u:
root
daemon
bin
sys
...
username

6. No output unless there is an error

7. No output unless there is an error

8. No output unless there is an error

11 | P a g e
9. Changing the password for group newgroup
New Password:
Re-enter new password:

10. No output unless there is an error

11. Removing user username from group groupname

12. Removing user username' ... Warning: group username' has no more members.
Done.

RESULT
The above commands are executed successfully and obtained desired output.

12 | P a g e
Experiment No : 04 Date : 4-09-2024

FILE AND DIRECTORY MANAGEMENT COMMANDS

AIM:
To familiarize with management of files and directories and its permissions using
Linux commands-ls, mkdir, cd, rmdir, touch, cp, mv, rm, chmod, chage, sudo, chown.
PROCEDURE:
1. Write command to list all files of the current directory
Command: $ls
2. Write command to display one file per line
Command: $ls -1
3. Write command to display all information about files/directories
Command: $ls -l
4. Write command to display directory information
Command: $ls –ld
5. Write command to display hidden files
Command: $ls -a
6. Write command to create a folder/directory named WPTC
Command: $mkdir GPCK
7. Write command to create a subfolder/subdirectory named CT in WPTC and S5 in
CT
Command: $mkdir -p WPTC/CT/S5
8. Write command to create the directory at desired location
Command: $mkdir /desired/path/directory_name
9. Write command to quickly go back
Command: $cd --
10. Write command to move up to one folder
Command: $cd ..
11. Write command to go back to the original location
Command: $cd –
12. Write command to create a new file named biodata.txt in directory S5

13 | P a g e
Command: $touch WPTC/CT/S5/biodata.txt
13. Write command to rename the file biodata.txt to biodata1.txt
Command: $mv WPTC CT/S5/biodata.txt WPTC/CT/S5/biodata1.txt
14. Write command to copy file in the current directory
Command: $cp file1.txt file1_copy.txt
15. Write command to copy file to another directory
Command: $cp file1.txt /path/to/destination/
16. Write command to remove a file
Command: $rm file1.txt
17. Write command to remove a directory
Command: $rmdir directory1
18. Write command to give read, write and execute permissions to the file owner
using symbolic mode
Command: $chmod o+rwx file1.txt
19. Write command to remove write permission for the group and others using
symbolic mode
Command: $chmod go-w file1.txt
20 .Write command to give read and write permission to the file Owner, read, write,
and executable permission to the Group, and read-only permission to Others using
octal mode
Command: $chmod 674 file1.txt
21. Write command to give read and write permission to the file Owner, read, write,
and executable permission to the Group, and read-only permission to Others using
octal mode
Command: $chmod 674 file1.txt
22. Write command to display the version number
Command: $uname -r
23. Write command to change the owner of a file
Command: $sudo chown newuser file1.txt
24. Write command to view and change the user password expiry information
Command: $chage -l username

14 | P a g e
OUTPUT:
1. file1.txt file2.txt directory1 directory2

2. file1.txt
file2.txt
directory1
directory2

3. -rw-r--r-- 1 user user 2048 Oct 5 12:34 file1.txt


-rw-r--r-- 1 user user 1024 Oct 5 12:30 file2.txt
drwxr-xr-x 2 user user 4096 Oct 5 12:25 directory1

4. drwxr-xr-x 2 user user 4096 Oct 5 12:34 directory1

5. . .. .hiddenfile file1.txt directory1

6. no output, creates the folder WPTC

7. no output, creates the nested folders

8. no output, creates the folder at the desired location

9. no output, changes back to the previous directory

10. no output, moves one level up

11. /previous/working/directory

12. no output, creates the file

13. no output, renames the file

14. no output, copies the file

15. no output, copies the file to the destination directory

16. no output, removes the file

17. no output, removes the empty directory

18. no output, permissions updated

15 | P a g e
19. no output, permissions updated

20. no output, permissions updated

21. no output, permissions updated

22. 5.11.0-37

23. no output, owner updated

24. Last password change : Oct 05, 2024


Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change 0
Maximum number of days between password change 99999
Number of days of warning before password expires 7

RESULT
The above commands are executed successfully and obtained desired output.

16 | P a g e
Experiment No : 05 Date : 4-09-2024

INPUT AND OUTPUT REDIRECTIONS ON LINUX

AIM:

To familiarize with the concept of input and output redirections on Linux

THEORY
Input Output Redirection in Linux
Input/output (I/O) redirection in Linux refers to the ability of the Linux operating
system that allows us to change the standard input ( stdin ) and standard output (
stdout ) when executing a command on the terminal. By default, the standard input
device is keyboard and the standard output device is screen.

For redirection, meta characters are used. Redirection can be into a file (shell meta
characters are angle brackets '<', '>') or a program ( shell meta characters are pipe
symbol '|').
Standard Streams In I/O Redirection
The bash shell has three standard streams in I/O redirection:
standard input (stdin) : The stdin stream is numbered as stdin (0). The bash shell
takes input from stdin. By default, keyboard is used as input.
standard output (stdout) : The stdout stream is numbered as stdout (1). The bash
shell sends output to stdout. Output goes to display.
standard error (stderr) : The stderr stream is numbered as stderr (2). The bash shell
sends error message to stderr. Error message goes to display.
Types of Redirection
1. Overwrite Redirection
Overwrite redirection is useful when you want to store/save the output of a
command to a file and replace all the existing content of that file. Commands
with a single bracket '>' overwrite existing file content.
o > : standard output
o < : standard input
o 2> : standard error

Note: Writing '1>' or '>' and '0<' or '<' is same thing. But for stderr you have to
write '2>'.
STANDARD OUTPUT REDIRECTION
Syntax
(cat-is used to copy the input and give the output to the screen)

17 | P a g e
1. cat >file.txt //standard output redirection- whatever you will write after
running this command, will be redirected and copied to the “file.txt”.
2. cat <file.txt // standard input redirection-Here cat command will take the input
from “file.txt” and print it to the terminal screen
3. cat 2>file.txt //standard error

Example
$cat >sample.txt
a
b
crl-z(save and exit)
$cat sample.txt
Output
a
b
$cat >sample.txt
c
d
$cat sample.txt
c
d
Egs
$ls -al > lists
$cat lists
$who > users
$cat users
2. Append Redirection
Append redirection is used to append the output to the file without
compromising the existing data of the file. Commands with a double bracket
'>>' do not overwrite the existing file content.
• >> - standard output
• << - standard input
• 2>> - standard error
Syntax
cat >>filename
Example
cat >>sample.txt
a
b
ctrl-z
cat sample.txt
a
b
18 | P a g e
cat >>sample.txt
c
d
cat sample.txt
a
b
c
d

REDIRECTION INTO A PROGRAM


Pipe redirects a stream from one program to another. When pipe is used to send
standard output of one program to another program, first program's data will not be
displayed on the terminal, only the second program's data will be displayed.

Example
$ls *.txt
$ls *.txt | cat >TextFiles
$cat TextFiles

STANDARD INPUT REDIRECTION


The ‘<‘ symbol is used for input(STDIN) redirection.
SYNTAX
cat <filename
Example
$cat < file.txt
a
b
$cat file.txt
For example, to count the number of lines in the file users
$wc-l users
$wc-l <users // count the number of lines in the file by redirecting the standard input
of the wc command from the file users
Egs.
$touch file.txt
$echo “Hello World”
O/P:Hello World
$echo “Hello World” >file.txt
$cat file.txt
$wc-l <file.txt or wc-l file.txt

RESULT
Familiarize the concept of input and output redirections on Linux.

19 | P a g e
Experiment No : 06 Date : 8-10-2024
PIPES AND FILTERS
AIM:
To familiarize with the usage of pipes and filters using Linux commands - wc, cut,
paste, comm, uniq, more, less, cmp, diff, sort, file sleep, grep.
PROCEDURE:
1. Write Linux command to create 3 files and display the contents of a file without
having to open it.
command: touch file1.txt file2.txt file3.txt
command: cat file1.txt
command: cat file2.txt
command: cat file3.txt

2. Write Linux command to count the no. of lines, words, and characters in file1.txt.
command: wc -lwm file1.txt

3. Write Linux command to count the no. of words in all files you created.
command: wc -w file1.txt file2.txt file3.txt

4. Write Linux command to list all files in a directory and count the number of lines
(files) listed.
command: ls | wc -l

5. Write Linux command to count the no. of characters in all .txt files.
command: cat *.txt | wc -c

6. Write Linux command to create a text file named state.txt with the following data
and display the first 3 characters (bytes) of each state.
Data:
Kerala

20 | P a g e
Tamilnadu
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
command: cut -b 1,2,3 state.txt

7. Write Linux command to:


a) Print second, fifth, and seventh characters from each line of state.txt.
command: cut -c 2,5,7 state.txt
b) Print starting from the first character to the end character.
command: cut -c 1- state.txt
c) Print starting from the first position to the fifth character.
command: cut -c -5 state.txt

8. Write Linux command to create a .csv file named data.csv with the following data
and extract columns.
Data:
Name, Age, Place
Anil, 16, Ernakulam
Vikram, 26, Kottayam
Seetha, 30, Idukki
Veena, 25, Kollam
a) Extract the second column (age).
command: cut -d',' -f2 data.csv
b) Print name and place fields.
command: cut -d',' -f1,3 data.csv
c) Print the first two columns.
command: cut -d',' -f1-2 data.csv

21 | P a g e
9. Write Linux command to list all logged-in users and extract their usernames.
command: who | cut -d' ' -f1

10. Write Linux command to print the first column of state.txt and store it in list.txt.
command: cat state.txt | head -n 3 | cut -d ' ' -f 1 > list.txt

11. Write Linux command to print the second word of the given message.
command: echo "hello world" | cut -d' ' -f2

12. Write Linux command to:


a) Merge files reg.txt and name.txt horizontally.
command: paste reg.txt name.txt
b) Merge files horizontally with a comma separator.
command: paste -d',' reg.txt name.txt
c) Merge files vertically.
command: paste -s reg.txt name.txt
d) Merge mark.txt with reg.txt and name.txt.
command: paste reg.txt name.txt mark.txt
e) Merge the output of echo with the content of mark.txt.
command: echo -e "Binu\nDone\nAmmu" | paste -d',' - mark.txt

13. Write Linux command to:


a) Sort both files and compare them.
command: sort file1.txt | sort file2.txt | comm - <(sort file2.txt)
b) Count the total number of lines output by comm.
command: comm file1.txt file2.txt | wc -l
c) Extract and print the second column, showing lines unique to file2.txt.
command: comm file1.txt file2.txt | awk '{print $2}'

22 | P a g e
d) Find common lines between two files, sort them, remove duplicates, and count the
unique common lines.
command: comm -12 <(sort file1.txt) <(sort file2.txt) | sort | uniq | wc -l

14. Write Linux command to:


a) View the contents of file1.txt using more command.
command: more file1.txt
b) Clear the screen before displaying.
command: more -c file1.txt
c) Print 4 lines at a time from the given file.
command: more -4 file1.txt
d) Start reading the file from the 4th line.
command: more +4 file1.txt

15. Write Linux command to:


a) Display line numbers of the given file.
command: less -N file1.txt
b) Open the file at a specific location.
command: less +N file1.txt
c) View multiple files at once.
command: less file1.txt file2.txt file3.txt

16. Write Linux command to list all files in a directory and view them one screen at a
time.
command: ls -l | more

17. Write Linux command to view a large file with better navigation features.
command: cat largefile.txt | less

23 | P a g e
18. Write Linux command to sort the contents of a file and view the sorted output with
less.
command: sort unsortedfile.txt | less

19. Write Linux command to compare two files file1 and file2.
command: diff file1.txt file2.txt

20. Write Linux command to:


a) View the differences of file1 and file2 in context mode and unified mode.
command: diff -c file1 file2
command: diff -u file1 file2

21. Write Linux command to suppress output and check differences in multiple files.
command: cmp -s file1.txt file2.txt && echo "Files are identical" || echo "Files are
different"

22. Write Linux command to count the differences between files using cmp.
command: cmp -l file1.txt file2.txt | wc -l

23. Write Linux command to compare files and filter out only the lines that differ.
command: diff --side-by-side file1.txt file2.txt | grep -E "(<|>)"

24. Write Linux command to sort the file marklist in alphabetical order.
command: sort marklist.txt

25. Write Linux command to sort the file marklist in numerical and reverse order.
command: sort -n marklist.txt
command: sort -nr marklist.txt

24 | P a g e
26. Write Linux command to find the type of a file and directory.
command: file marklist.txt
command: file /home

27. Write Linux command to search for a pattern in a given file.


command: grep "99" marklist.txt

28. Write Linux command to list files containing the pattern “scanf” in file.c.
command: grep -l "scanf" file.c

29. Write Linux command to sort lines containing a specific pattern.


command: grep "o" fruit.txt | sort

30. Write Linux command to sort unique lines from a file and search for a pattern.
command: sort -u fruit.txt | grep "a"

31. Write Linux command to count the number of lines, words, and characters in files
that contain the word "n" and then sort them.
command: grep -i "n" fruit.txt | wc -l | sort -n

32. Extract the second column from a CSV file, sort it, remove duplicates, and count
the unique entries.
command: cut -d, -f2 file.csv | sort | uniq | wc -l

33. Compare two sorted files line by line and display the lines common to both.
command: comm -12 <(sort file1.txt) <(sort file2.txt)

34. Compare two files and show the differences or confirm they are identical.
command: diff file1.txt file2.txt

25 | P a g e
command: cmp file1.txt file2.txt

35. Determine the type of a file and display its content.


command: file example.txt | less

36. Wait for a few seconds, then list all files in a directory that match a pattern.
command: sleep 5 && ls | grep ".sh"

37. Sort a list of words, remove duplicates, and count how many unique words exist.
command: sort fruits.txt | uniq | wc -l

38. Extract and combine specific fields from lines in a text file that match a pattern.
command: grep "a" fruit.txt | cut -d' ' -f1,3 | paste -sd " "

39. Find and display the most frequent lines in a file.


command: sort file.txt | uniq -c | sort -nr | head

40. Search for a pattern in a file and view the results with pagination.
command: grep "search_term" file.txt | less

26 | P a g e
OUTPUT:
1. (no output generated as files are empty)

2. 0 0 0 file1.txt

3. 0 file1.txt
0 file2.txt
0 file3.txt
0 total

4. 3

5. 0

6. Ker
Tam
And
Aru
Ass
Bih

7a. e l h
7b. Kerala
Tamilnadu
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
7c. Keral
Tamil
Andhr

27 | P a g e
Arunac
Assam
Bihar

8a. 16
26
30
25
8b. Anil, Ernakulam
Vikram, Kottayam
Seetha, Idukki
Veena, Kollam
8c. Anil, 16
Vikram, 26
Seetha, 30
Veena, 25

9. (list of logged-in users will vary)

10. Kerala
Tamilnadu
Andhra

11. world

12a. 1250 Binu


1251 Done
1356 Ammu
12b. 1250, Binu
1251, Done

28 | P a g e
1356, Ammu
12c. 1250 1251 1356
Binu Done Ammu
12d. 1250 Binu 60
1251 Done 90
1356 Ammu 80
12e. Binu,60
Done,90
Ammu,80
13a. 2
3
4
5
6
13b. 7
13c.6
13d.4
14a. 1
2
3
4
5
14b. 1
2
3
4
5
14c. 1
2

29 | P a g e
3
4
14d. 4
5
15a. 1 1
2 2
3 3
4 4
5 5
6
15b. opens at specified line
15c. 1 2 5
2 3 6
3 4 7
4 5 8
5 6 9
16. -rw-rw-r-- 1 user user 57 Sep 28 14:25 a.c
-rw-rw-r-- 1 user user 0 Aug 31 22:39 aleena.txt
-rw-rw-r-- 1 user user 68 Sep 28 13:31 data.csv
-rwxrwxr-x 1 user user 309 Oct 8 14:26 day.sh
……….
17. view large file with navigation
18. aleena
anagha
nisa
nitty
sahva
sara
shivakami

30 | P a g e
19. 1d0
<1
6c5
<
---
>6
20. *** file1.txt 2024-10-10 23:49:24.036285776 +0530
--- file2.txt 2024-10-10 23:49:36.189752640 +0530
***************
*** 1,6 ****
-1
2
3
4
5
!
1,5
2
3
4
5
!6
--- file1.txt 2024-10-10 23:49:24.036285776 +0530
+++ file2.txt 2024-10-10 23:49:36.189752640 +0530
@@ -1,6 +1,5 @@
-1
2
3
4
5
+6
21. Files are different
22. cmp: EOF on file2.txt after byte 10
5

31 | P a g e
23. 1
24. 12
23
56
78
99
25. 12
23
56
78
99

99
78
56
23
12
26. marklist.txt: ASCII text
27.99
28. file.c
29. avocado
Lemon
Mango
Melon
Orange
30. apple
avacado
banana
mango
orange
pineapple
31. 6
32. 3

32 | P a g e
33. 2
3
4
5
34. 1d0
<1
6c5
<
---
>6
file1.txt file2.txt differ: byte 1, line 1
35. file1.txt: ASCII text
36. files matching pattern after wait
day.sh
fact.sh
forloop.sh
large3.sh
multable.sh
natural.sh
37. 9
38. orange apple mango pineapple banana avocado
39. 1 5
14
13
12
11
40. orange
mango
melon
lemon
avacado
(END)
RESULT
The above commands are executed successfully and obtained desired output.

33 | P a g e
Experiment No : 07 Date : 8-10-2024

PROCESS MANAGEMENT COMMANDS


AIM:

Demonstrate process management using commands - bg, fg, top, ps, pidof, nice,
renice, df, free, kill, pkill.

PROCEDURE:
1. Write command and start a long-running process (e.g., sleep 300), send it to the
background, and then bring it back to the foreground.
command: sleep 300
command: bg
command: fg

2. Write command and use the top command to identify the process consuming the
most CPU and memory. What are the PIDs of these processes?
command: top

3. Write command and list all processes running under your user account and identify
the PID of the shell you're currently using.
command: ps -u $USER

4. Write command and find the PID of the bash shell and the sshd daemon (if
running). What are the PIDs?
command: ps
command: pidof bash
command: pidof sshd

5. Write command and start a process with a lower priority using nice, then use renice
to increase its priority.
command: nice -n 10 sleep 600
command: ps -o pid,nice,command | grep sleep
34 | P a g e
command: renice -n 0 -p <PID>
command: ps -o pid,nice,command | grep sleep

6. Write command and use the df command to check disk space usage and the free
command to check memory usage.
command: df -h
command: free -h

7. Write command and start a process (e.g., sleep 600), find its PID using ps, and then
terminate it using kill.
command: sleep 600 &
command: ps
command: kill <PID>

8. Write command and start two instances of a process (e.g., sleep 600 & sleep 600
&). Use pkill to terminate both at once.
command: sleep 600 & sleep 600 &
command: pkill sleep
command: ps | grep sleep

9. Write command and Run top and observe the system's load average, memory usage,
and swap usage.
command: top

10. Write command and start a CPU-intensive task (e.g., yes > /dev/null) and use
renice to reduce its priority.
command: yes > /dev/null &
command: ps -o pid,nice,command | grep yes
command: renice 10 -p <PID>
command: top

35 | P a g e
OUTPUT
1.
[1]+ Stopped sleep 300
[1]+ sleep 300 &

2. %CPU and %MEM values displayed for each process in the top output.

3.
PID TTY TIME CMD
1528 pts/0 00:00:00 bash
1586 pts/0 00:00:00 ps

4. 1528
N/A (sshd not running)

5. PID NI COMMAND
1683 10 sleep
1683 0 sleep

6.
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev

total used free shared buff/cache available Mem:


15Gi 4Gi 6Gi 0.1Gi 4Gi 10Gi Swap:
2Gi 0Gi 2Gi

36 | P a g e
7. PID TTY TIME CMD
1683 pts/0 00:00:00 sleep
[1] + Terminated sleep 600

8.
[1] 1685
[2] 1686

[1]- Terminated sleep 600


[2]+ Terminated sleep 600

9.
Load average: 0.34, 0.22, 0.14
Memory usage: 4Gi used out of 15Gi
Swap usage: 0Gi used

10.
PID NI COMMAND
1688 0 yes
1688 10 yes

RESULT
The above commands are executed successfully and obtained desired output.

37 | P a g e
Experiment No : 08 Date : 9-09-2024
BACK UP AND RECOVERY MANAGEMENT
AIM:
Demonstrate backup and recovery management using commands tar, cpio, dump
THEORY
• Backup and recovery management are essential tasks for safeguarding data. In
Linux tar,
• cpio, and dump are commonly used for creating backups and recovering data.
• tar: Best for general-purpose backups, supports compression.
• cpio: Useful for more complex file selections, often used with find.
• dump/restore: Ideal for full and incremental backups of entire file systems.
1. Using tar for Backup and Recovery
The tar command (short for "tape archive") is widely used for creating archive files,
which can
be compressed and then extracted to recover data.
Backup with tar
• Backup a directory /home/user/data into an archive file.
o Command:
$ tar -cvf backup.tar /home/user/data
Options:
-c: Create a new archive.
-v: Verbose mode, shows progress.
-f backup.tar: Specify the archive file name.
Description: This command creates a backup.tar archive containing the
contents of /home/user/data.
• Compressed Backup:
$ tar -czvf backup.tar.gz /home/user/data
Options:
-z: Compress the archive with gzip.
Recovery with tar
Scenario: Recover (extract) the data from the backup.tar archive to
/home/user/recovery.
Command:
$ tar -xvf backup.tar -C /home/user/recovery
o Options:

38 | P a g e
-x: Extract the archive.
-C /home/user/recovery: Extract files into the specified directory.

$ tar -xzvf backup.tar.gz -C /home/user/recovery


2. Using cpio for Backup and Recovery
The cpio command is used to copy files to and from archives, often in conjunction
with find or ls commands.
Backup with cpio

$ find /home/user/data -name "*.txt" | cpio -ov > backup.cpio


o Options:
-o: Create an archive.
-v: Verbose mode.
o Description: This command finds all .txt files and archives them into
backup.cpio.
Recovery with cpio

$ cpio -iv < backup.cpio -d -u -D /home/user/recovery


o Options:
-i: Extract files.
-v: Verbose mode.
-d: Create directories as needed.
-u: Overwrite existing files.
-D /home/user/recovery: Change directory before extracting
files.
3. Using dump for Backup and restore for Recovery
The dump command is used for backing up entire file systems, and restore is used to
recover from those backups.
Backup with dump

39 | P a g e
$ dump -0uf backup.dump /home
o Options:
-0: Perform a level 0 (full) backup.
-u: Update the /etc/dumpdates file after a successful dump.
-f backup.dump: Specify the output file.
o Description: This command creates a full backup of the /home filesystem in
backup.dump.
Incremental Backup with dump
enario: Perform an incremental backup (level 1) of /home.

$ dump -1uf backup_level1.dump /home


o Options:
-1: Perform a level 1 (incremental) backup.
Recovery with restore
e.

$ restore -rf backup.dump -D /home/recovery


o Options:
-r: Restore the entire file system.
-D /home/recovery: Specify the recovery directory.

$ restore -if backup.dump


o Options:
-i: Interactive mode, allows selecting specific files/directories to restore.
RESULT
The above commands are executed successfully and obtained desired output.

40 | P a g e
Experiment No : 09 Date : 9-09-2024

FAMILIARIZATION OF SHELL AND TYPES OF SHELLS


USED IN LINUX OS DATE:
AIM:
Demonstrate the concept of shell and types of shells used in Linux Operating System
THEORY
Creating a shell script to manage systems can involve various tasks such as
monitoring system performance, managing processes, handling backups, updating
software, and more. Concept of Shell in Linux

1. Definition:
A shell is a command-line interpreter that provides a text-based interface
o
for users to interact with the operating system. o It takes
commands from the keyboard and passes them to the operating system
to perform tasks. 2. Functions of a Shell:
o Command Execution: Executes commands entered by the user. o
Scripting: Allows users to write shell scripts to automate tasks. o
Program Execution: Runs programs and commands. o
Environment Control: Manages environment variables and
configurations.
o Input/output Redirection: Redirects input and output of commands to
files or other commands.
3. Types of Shells in Linux

There are several types of shells available in Linux, each with its own features and
syntax. Here are some of the most common ones:

1. Bourne Shell (sh)

• Overview: The original Unix shell developed by Stephen Bourne at AT&T


Bell Labs. It is the predecessor of many modern shells.
• Features:
o Simple and minimalistic.
o Used in many Unix-like operating systems.
o Basic scripting capabilities.
• Example:

sh

• Usage: Although it has been largely replaced by more modern shells, sh is still
used in scripting and system scripts due to its portability.

41 | P a g e
2. Bourne-Again Shell (bash)
• Overview: bash (Bourne-Again SHell) is an enhanced version of the original
Bourne Shell. It is the default shell on most Linux distributions.
• Features:
o Command-line editing. o Command history. o Advanced
scripting capabilities (e.g., arrays, functions).
o Supports features like brace expansion, command substitution, and
more. Example:

bash

• Usage: bash is the most widely used shell in the Linux world due to its
powerful features and backward compatibility with sh.

3. C Shell (csh)

• Overview: csh was developed by Bill Joy at the University of California,


Berkeley. It was designed with C-like syntax to appeal to C programmers.
• Features:
o C-like syntax for programming. o Alias creation for commands.
o Job control. Example:

csh

• Usage: csh is less commonly used today but is still favored by some developers
who prefer its C-like syntax.

4. Korn Shell (ksh)

• Overview: Developed by David Korn at AT&T Bell Labs, ksh combines


features of the Bourne shell with the scripting capabilities of the C shell.
• Features:
o Enhanced scripting capabilities.
o Command-line editing.
o Built-in arithmetic operations. o Faster execution than csh. Example:

ksh

• Usage: ksh is popular in commercial environments due to its efficiency and


powerful features.

5. Z Shell (zsh)
• Overview: zsh is a highly customizable and feature-rich shell that combines the
best features of bash, ksh, and tcsh.
• Features:
o Command-line completion.

42 | P a g e
Plugin support (e.g., Oh My Zsh). o
o Advanced scripting features. o
Theme support.
o Built-in spell check and autocorrect.
• Example:

zsh

• Usage: zsh is becoming increasingly popular, especially among developers, due


to its customization capabilities and user-friendly features.

Fish Shell (fish)

• Overview: fish (Friendly Interactive SHell) is designed to be user-friendly with


intuitive features.
• Features:
o Automatic suggestions and syntax
highlighting. o Web-based
configuration.
o No need to set up configuration files.
• Example:

fish

• Usage: fish is favored by users looking for a more interactive and user-friendly
shell experience.

Comparison of Shells
Feature sh bash csh ksh zsh fish
Default on No Yes No No No No
Linux
Command- No Yes No Yes Yes Yes
line Editing
Command No Yes Yes Yes Yes Yes
History
Scripting Basic Advanced Moderate Advanced Advanced Moderate
Features
Customization No Yes No No Yes Yes
& Plugins
User- Basic Good Basic Good High High
friendliness

43 | P a g e
Demonstration Example
Let's switch between different shells and demonstrate their use:
BASH
$ bash # Starts the
bash shell $ echo
"Hello from bash!"
Hello from bash!

ZSH
$ zsh # Switches to
zsh shell % echo
"Hello from zsh!"
Hello from zsh!
CSH
% csh # Switches to
csh shell % echo
"Hello from csh!"
Hello from csh!

We can return to the default shell by typing exit in any of the shells:

$ exit # Exit zsh and return to bash


$ exit # Exit bash and return to the original shell

RESULT

Familiarized with Linux Operating System Shell and types of shells.

44 | P a g e
Experiment No : 10 Date : 8-10-2024

SHELL SCRIPTING
AIM:

To write shell scripts for performing basic arithmetic operations, decision making, looping
constructs, case structures, and function implementation to automate simple tasks.
I. Shell program to add 2 numbers
#!/bin/bash
echo -n "Enter the first number: "
read num1
echo -n "Enter the second number: "
read num2
let sum=num1+num2
echo "The sum = $sum"
II. Shell program to print whether a number is odd or even
#!/bin/bash
read -p "Enter a number: " num
let remainder=num%2
if [ $remainder -eq 0 ]; then
echo "The number is an even number"
else
echo "The number is an odd number"
fi
III. Shell program to print whether a number is positive, negative or zero
#!/bin/bash
read -p "Enter a number: " num
if [ $num -gt 0 ]; then
echo "The number is a positive number"
elif [ $num -lt 0 ]; then
45 | P a g e
echo "The number is a negative number"
else
echo "The number is zero"
fi
IV. Shell program to print the largest of 3 numbers
#!/bin/bash
read -p "Enter the first number: " num1
read -p "Enter the second number: " num2
read -p "Enter the third number: " num3
if [[ $num1 -ge $num2 ]] && [[ $num1 -ge $num3 ]]; then
echo "The largest number is $num1"
elif [[ $num2 -ge $num1 ]] && [[ $num2 -ge $num3 ]]; then
echo "The largest number is $num2"
else
echo "The largest number is $num3"
fi
V. Shell program to print the first N natural numbers
#!/bin/bash
read -p "How many natural numbers: " n
let i=1
while [ $i -le $n ]; do
echo $i
let i++
done

VI. Shell program to print the first N natural numbers in reverse order
#!/bin/bash
read -p "How many natural numbers: " n
let i=$n

46 | P a g e
until [ $i -eq 0 ]; do
echo $i
let i--
done
VII. Shell program to print the first 10 natural numbers using for loop
#!/bin/bash
echo "The first 10 natural numbers:"
for i in {1..10}; do
echo $i
done
VIII. Shell program to print the multiplication table of 8
#!/bin/bash
let j=1
for i in {8..80..8}; do
echo "$j x 8 = $i"
let j++
done
IX. Shell program to print the sum of N numbers
#!/bin/bash
read -p "How many numbers: " n
let sum=0
echo "Enter the numbers:"
for (( i=0; i<$n; i++ )); do
read x
let sum=sum+x
done
echo "The sum of the numbers is: $sum"
X. Shell program to print the day of week given a number between 1 and 7
#!/bin/bash

47 | P a g e
read -p "Enter the day of the week as a number between 1 and 7: " n
case $n in
1) echo "Monday" ;;
2) echo "Tuesday" ;;
3) echo "Wednesday" ;;
4) echo "Thursday" ;;
5) echo "Friday" ;;
6) echo "Saturday" ;;
7) echo "Sunday" ;;
*) echo "Invalid input" ;;
esac
XI. Shell program to print the factorial of a number using function
#!/bin/bash
factorial() {
let n=$1
let fact=1
for ((i=1;i<=$n;i++)); do
let fact=fact*i
done
echo "The factorial = $fact"
}

read -p "Enter a number: " num


factorial $num

48 | P a g e
OUTPUT:

1. Enter the first number: 5


Enter the second number: 10
The sum = 15

2. Enter a number: 4
The number is an even number
Enter a number: 3
The number is an odd number

3. Enter a number: -2
The number is a negative number
Enter a number: 2
The number is a positive number
Enter a number: 0
The number is zero
4. Enter the first number: 7
Enter the second number: 12
Enter the third number: 3
The largest number is 12
5. How many natural numbers: 5
1
2
3
4
5
6. How many natural numbers: 5
5
4
3
2
1

49 | P a g e
7. The first 10 natural numbers:
1
2
3
4
5
6
7
8
9
10
8. 1x8=8
2 x 8 = 16
3 x 8 = 24
4 x 8 = 32
5 x 8 = 40
6 x 8 = 48
7 x 8 = 56
8 x 8 = 64
9 x 8 = 72
10 x 8 = 80
9. How many numbers: 3
Enter the numbers:
2
3
5
The sum of the numbers is: 10
10. Enter the day of the week as a number between 1 and 7: 4
Thursday

11. Enter a number: 5


The factorial = 120
RESULT
The above commands are executed successfully and obtained desired output.

50 | P a g e

You might also like