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

linuxpdf

The document outlines the Linux Shell Programming Lab curriculum for B. Tech students at Geetanjali Institute of Technical Studies for the academic year 2024-25. It includes a detailed index of experiments covering basic Unix shell commands, shell scripting, control structures, and functions, along with example scripts and their expected outputs. Additionally, it provides a rubric for evaluating student performance based on criteria such as understandability, logic, debugging ability, and correctness.

Uploaded by

raodimple848
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)
14 views

linuxpdf

The document outlines the Linux Shell Programming Lab curriculum for B. Tech students at Geetanjali Institute of Technical Studies for the academic year 2024-25. It includes a detailed index of experiments covering basic Unix shell commands, shell scripting, control structures, and functions, along with example scripts and their expected outputs. Additionally, it provides a rubric for evaluating student performance based on criteria such as understandability, logic, debugging ability, and correctness.

Uploaded by

raodimple848
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/ 18

Geetanjali Institute of Technical Studies

(Approved by AICTE, New Delhi and Affiliated to Rajasthan Technical University, Kota (Raj.))
DABOK, UDAIPUR, RAJASTHAN 313022

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


B. Tech - IV SEMESTER

ACADEMIC YEAR – 2024-25

Linux Shell Programming Lab

4CS4-24

Submitted To Submitted By:


Pankaj Kumar Vaishnav Dipesh Soni
23EGICS042
A
INDEX

Date of
Date of
S.NO Experiment Name Submissio Signature
issue
n
1 Use of Basic Unix Shell Commands: ls, mkdir, rmdir, cd, cat, touch,
file, wc, sort, cut, grep.

2 Commands related to inode, I/O redirection and piping, process control


commands, mails.

3 Shell Programming: Shell script based on control structure- If-then-fi,


if-then else-if, nested if-else, to find:
3.1 Greatest among three numbers.
3.2 To find a year is leap year or not.
4 3.3 To input angles of a triangle and find out whether it is valid
triangle or not.
3.4 To check whether a character is alphabet, digit or special
character.
3.5 To calculate profit or loss.
5 Shell Programming - Looping- while, until, for loops
4.1 Write a shell script to print all even and odd number from 1 to 10
4.2 Write a shell script to print table of a given number.
6 4.3 Write a shell script to calculate factorial of a given number.
4.4 Write a shell script to print sum of all even numbers from 1 to 10.
4.5 Write a shell script to print sum of digit of any number.
7 5. Shell Programming - case structure, use of break
5.1 Write a shell script to make a basic calculator which performs
addition, subtraction, Multiplication, division.
8 5.2 Write a shell script to print days of a week.
5.3 Write a shell script to print starting 4 months having 31 days.

9 Shell Programming - Functions


6.1 Write a shell script to find a number is Armstrong or not.
6.2 Write a shell script to find a number is palindrome or not.
10 6.3 Write a shell script to print Fibonacci series.
6.4 Write a shell script to find prime number.
6.5 Write a shell script to convert binary to decimal and decimal to
binary.
11 Write a shell script to print different shapes- Diamond, triangle, square,
rectangle, hollow square etc.

12 Shell Programming – Arrays


8.1 Write a C program to read and print elements of array.
8.2 Write a C program to find sum of all array elements.
13 8.3 Write a C program to find reverse of an array.
8.4 Write a C program to search an element in an array.
8.5 Write a C program to sort array elements in ascending or
descending order.
EXPERIMENT NO:- 1, 2

1. Use of Basic Unix Shell Commands: ls, mkdir, rmdir, cd, cat, banner, touch, file, wc, sort, cut,
grep, dd, dfspace, du, ulimit.
2. Commands related to inode, I/O redirection and piping, process control commands, mails.

1. ls : Listing files (command list directory contents)


Syntax - $ls
Example - $ls (display all files beginning with the string l)
The (*) is “wildcard” character.
Output:-

2. mkdir : Make Directories (use this command to create a directory)


Syntax - $mkdir [directory name]
Example - mkdir newdirectory

3. rmdir : Remove directories (use this command to remove directory)


Syntax - $rmdir [directory name]
Example - rmdir newdirectory
Options:- rm –r directory name will remove all files even if directory is not empty.
rmdir –r will remove directory& any present directory that are empty.
Output:-

4. cd : change directories (command is used to change the current working/present directory)


Syntax - $cd [directory name]
Example - $cd scripting
Output:-
5. cat : create file, display content of file, concatenate files
You can create a file without a text editor by using the cat command and “>>” (Redirect output) symbol.
To create a file using cat command, type
Syntax - $cat file_name (display content)
- $cat file_name1 file_name2 >> merge_file
Example - $cat file.txt
Output:-

6. banner : command in linux is used to print the ASCII character string in large letter to standrad output.
Syntax - $banner ASCII value
Output:-

7. touch : command is a standard command used in unix/linux operating system which is used to create,
change and modify timestamps of a file.
touch command: It is used to create a file without any content. The file created using touch command
is empty. This command can be used when the user doesn’t have data to store at the time of file creation.
Syntax - $touch file_name
Output:-
8. du : used disk space (du - stands for disk usage)
This command is used to show the amount of disk space consumed by one or more files or directory (or
directory trees.
Syntax - $du
Output:-

9. ulimit : user status (ulimit – stands for user limit)


This command shows the user space.
Syntax - $ulimit
Output:-

10. wc : Print byte, word, and line counts, count the no. of bytes, whitespace- separated words,
and newlines in each given FILE
Syntax - $wc [options] [File]
Options
--bytes
-c Print only the byte counts.
--chars
-w --words Print only the word counts.
-l --lines Print only the newline counts.
Output:-
11. grep : search for a string or word in a file
Syntax - $grep option filename
Output:-

12. df : free disk space int MB.


The df command present in/etc directory
Syntax - $df file or directory
Output:-

13. sort : sorting a file


Write sorted concatenation of all FILE(s) to standard output.
Syntax - $sort [file name]
Example - $sort file1
Output:-
14. cut : command in UNIX is a command for cutting out the sections from each line of files and writing the
result to standard output. It can be used to cut parts of a line by byte position, character and field.

Basically the cut command slices a line and extracts the text. It is necessary to specify option with command
otherwise it gives error. If more than one file name is provided then data from each file is not precedes by its
file name.
Syntax - $cut [option] [file]
Output:-

15. pwd : print name of current/working directory


This command print the full filename of the current working directory.
Syntax - $pwd
Output:-

16. echo : display a line of text


echo the STRING(s) to standard output.
Syntax - $echo [short-option] [string]
Output:-

17. diff : compare file line by line


echo the STRING(s) to standard output.
Syntax - $diff filename1 filename2
Output:-
18. man : an interface to the system reference manuals
man is the system's manual pager. Each page argument given to man is normally the name of a program,
utility or function.
Syntax - $man [commands]
Output:-

19. man : copy files and set attribute


This install program copies files (often just compiled) into destination locations you choose.
Syntax - $install [option]... [-T] source dest
Output:-

20. bc : an arbitrary precision calculator language


Syntax - $bc [ -hlwsqv ] [long-options] [file]
Output:-

21. dd : convert and copy a file


Copy a file, converting and formatting according to the operands.
Syntax - $dd [options]
Output:-
22. cal : displays a calendar and the date of Easter
Syntax - $cal mm yyyy

23. date : print or set the system date and time


Syntax - $date

24. time : run programs and summarize system resource usage


time run the program command with any given arguments arg.... When command finishes, time
displays information about resources used by command.
Syntax - $time [ --help ] command [ args ]
Output:-

25. file : determine file type


file tests each argument in an attempt to classify it.
Syntax - $file file_name
Output:-

26. find : search for files in a directory hierarchy


find searches the directory tree rooted at each given starting-point by evaluating the given expression from
left to right.
Syntax - $find file_name
Output:-
27. tty : print the file name of the terminal connected to standard input
Print the file name of the terminal connected to standard input.
Syntax - $tty
Output:-

28. hostname : show or set the system's host name


Syntax - $hostname
Output:-

29. uname : print system information


Syntax - $uname
Output:-

30. sudo : execute a command as another user


sudo allows a permitted user to execute a command as the superuser or another user, as specified by the
security policy.
Syntax - $sudo
Output:-

31. tar : an archiving utility


GNU tar is an archiving program designed to store multiple files in a single file (an archive), and to
manipulate such archives.
Syntax - $tar
Output:-
32. who : show who is logged on
Syntax - $who [option] [file arg1 arg2]
Output:-

33. history : GNU history library


Syntax - $history
Output:-

34. ps : report a snapshot of the current processes


ps displays information about a selection of the active processes.
Syntax - $ps [option]
Output:-

35. head : the head command to print the first few entries of a file.
Syntax - $head filename

36. tail : tail command is the opposite of head, allowing you to print the last few lines from files or another
utility’s output.
Syntax - $tail filename
Output:-
37. pipe : a pipe (represented by the | symbol) is a powerful tool that allows you to connect the output of one
command to the input of another, creating a chain of commands for efficient data processing.
Syntax - command | command
Output:-

38. zip : package and compress (archive) files


Syntax - $zip [options] zip_file_name file1 file2

39. unzip : package and compress (archive) files


Syntax - $unzip zip_file_name
Output:-

40. kill : send a signal to a process


Syntax - $kill [options]
Output:-

41. nano : commands let you edit files


Syntax - $nano filename
Output:-
42. whoami : currently logged-in user from the Linux command-line shell
Syntax - $whoami
Output:-

43. top : command displays all running processes in your system and their hardware consumption
Syntax - $top [option]
Output:-

44. ip : shutdown command lets you turn off or restart your Linux system at a specific time
Syntax - $ip [option] [time] [message]
Output:-

45. netstat : displays information about your system’s network configuration


Syntax - $netstat [options]
Output:-

46. nslookup : command requests a domain name system (DNS) server to check a domain linked to an IP
address or vice versa
Syntax - $nslookup [options] domain-or-ip [dns-server]
Output:-
EXPERIMENT No:- 3
control structure

Q 3.1: Write a shell script to find Greatest among three numbers.


solution :-
echo "Enter the first number: "
read num1
echo "Enter the second number: "
read num2
echo "Enter the third number: "
read num3

if [[ $num1 -ge $num2 && $num1 -ge $num3 ]] then


echo "$num1 is the greatest"
elif [[ $num2 -ge $num1 && $num2 -ge $num3 ]] then
echo "$num2 is the greatest"
else
echo "$num3 is the greatest"
fi
output :-

------------------------------------------------------------------------------------------------------------------------------------------------------------------

Q 3.2: Write a shell script to find a year is leap year or not.


solution :-
read year

# Check if the year is a leap year


if [[ $(($year % 400)) -eq 0 ]] then
echo "$year is a leap year"
elif [[ $(($year % 100)) -eq 0 ]] then
echo "$year is not a leap year"
elif [[ $(($year % 4)) -eq 0 ]] then
echo "$year is a leap year"
else
echo "$year is not a leap year"
fi
output :-
Q 3.3: Write a shell script take input angles of a triangle and find out whether it is valid triangle or not.
solution :-
echo "Enter first angle:- "
read a
echo "Enter second angle:- "
read b
echo "Enter third angle:- "
read c

# condition for triangle validity


if [[ $a -gt 0 && $b -gt 0 && $c -gt 0 && $(($a + $b + $c)) -eq 180 ]]
then
echo "The angles form a valid triangle."
else
echo "The angles do not form a valid triangle."
fi
output :-

------------------------------------------------------------------------------------------------------------------------------------------------------------------

Q 3.4: Write a shell script to check whether a character is alphabet, digit or special character.
solution :-
echo "enter a char"
read c

# condition for serach


if [[ $c == [A-Z] ]]
then
echo "upper"
elif [[ $c == [a-z] ]]
then
echo "lower"
elif [[ $c == [0-9] ]]
then
echo "digit"
else
echo "special symbols!"
fi
output :-

------------------------------------------------------------------------------------------------------------------------------------------------------------------

Q 3.5: Write a shell script to calculate profit or loss.


solution :-
echo "investment :- "
read i
echo "return :- "
read r

#condition for profit and loss


if [[ $r -ge $i ]] then
echo "Profit"
else
echo "loss"
fi
output :-
Rubrics Evaluation

Performance Scale 1 Scale 2 Scale 3 Scale 4 Score


Criteria (0-25%) (26-50%) (51-75%) (76-100%) (Numeric
al)

Understandabil Unable to Able to Able to Able to understand the


ity understand understand understand problem completely
the the problem the problem and able to provide
problem. partially completely alternativesolution too.
Ability to andunable to but unable
analyseProblemand identify the to identify
Identify solution solution the solution
Logic Program Program Program Program logic is
logic is logic is on logic is correct,with no known
Ability to specify incorrect theright track mostlycorrec boundaryerrors, and no
Conditions& control but has t, but may redundantorcontradictoryc
flow that several contain onditions.
areappropriate for the errors an
occasional
problem domain. boundaryerr
or or
redundant or
contradictory
condition.
Debugging Unabletoexe Unable to Able to Able to execute program
Ability to execute cute program debug several execute completely
/debug errors. program with
several
warnings.
Correctness Program Program Program Program produces
Ability to code does not approachescor produces correctanswers or
formulae and producecorre rect answers correctanswer appropriateresults for all
algorithms that ct answers orappropriate s or inputs tested.
reliably produce orappropriat results appropriateres
correct answers or e results formost ults for most
appropriate results. formost inputs, but inputs.
inputs. cancontain
miscalculatio
ns insome
cases.
Completeness Unable to Unable to Able to Able to explain code and the
Ability to explain the explain the explain code program was delivered on
demonstrate and code.and the code and the and the time.
deliver on time. code code program was
wasoverdue. submission delivered
was late. within the due
date.
Computer Lab’s Do’s and Don’t and Safety Rules
DO’s
 Please switch off the Mobile/Cell phone before entering Lab.
 Check whether all peripheral are available at your desktop before proceeding for the session
 Arrange all the peripheral and seats before leaving the lab.
 Properly shutdown the system before leaving the lab.
 Keep the bag outside in the racks.
 Enter the lab on time and leave at proper time.
 Maintain the decorum of the lab.

DON’TS
 Don’t mishandle the system.
 Don’t leave the system on standing for long
 Don’t bring any external material in the lab.
 Don’t make noise in the lab.
 Don’t bring the mobile in the lab.
 Don’t enter in the lab without permission of lecturer/laboratory technician immediately
 Don’t delete or make any modification in system files.
 Don’t bring storage devices like pen drive without permission of lecturer/laboratory
technician.

Computer Lab Safety Rules


 Know the location of the fire extinguisher and how to use them in case of an emergency.
 Report fires or accidents to your lecturer/laboratory technician immediately
 Report any broken plugs or exposed electrical wires to your lecturer/laboratory technician
immediately.
 Avoid stepping on electrical wires or any other computer cables.
 Do not open the system unit casing or monitor casing particularly when the power is turned
on.
 Do not touch, connect or disconnect any plug or cable without your lecturer/laboratory
technician’s permission.
 Do not bring any food or drinks near the machine.

You might also like