Linux Lab Manual
Linux Lab Manual
Linux Lab Manual
PROGRAMMING LAB –
LINUX & SHELL PROGRAMMING
S. No Title
Shell script to stimulate the file commands: rm, cp, cat, mv, cmp, wc, split,
1.
diff.
shell script to show the following system configuration :
a. currently logged user and his log name
b. current shell , home directory , Operating System type , current
2. Path setting , current working directory
c. show currently logged number of users, show all available shells
d. show CPU information like processor type , speed
e. show memory information
Shell Script to implement the following: pipes, Redirection and tee
3.
commands.
Shell script for displaying current date, user name, file listing and directories
4.
by getting user choice
6. Shell script to remove the files which has file size as zero bytes
7. Shell script to find the sum of the individual digits of a given number.
Shell script to find the greatest among the given set of numbers using
8.
command line arguments.
Shell script to print the multiplication table of the given argument using for
10.
loop.
Ex:1
Shell script to stimulate the file commands: rm, cp, cat, mv, cmp, wc, split, diff.
AIM:
To stimulate the file commands rm,cp,cat,mv,wc,split,diff.
ALGORITHM:
Step 1: Start the program.
Step 2: Using touch command create file 1 file2, file3 ,file4 and file 5 as textfiles.
Step 3: Using rm command remove file1. txt.
Step 4: Copy the file2 to file3 using cp command.
Step 5: Using cat command display the contents of file 3 and file 4. Step 6:
Using wc command return the number of lines of the file 3.
Step 7: Using diff command compare two file4 and file5
Shell script:-
rm file1.txt
echo "file1 successfully deleted"
echo " "
cp file2.txt file3.txt
echo "file2 successfully copied to file3"echo "
"
echo "content of file3 and file4"cat
file3.txt output file4.txt echo " "
echo "total no.of lines in a file3"wc
file3.txt
echo " "
echo "compare two files file4 and file5"diff
file4.txt file5.txt
echo " "
Output:
RESULT:
AIM:
To script to show the following system configuration.
a) Currently logged user and his log name
b) Current shell, home directory, os type, current path, current workingdirectory.
c) show currently logged number of user, show all available shell
d)Show the CPU information like process, type, speed etc.
e) Show the memory information.
ALGORITHM:
Shell script:-
echo "current login user:"$(whoami) //echo "
"
echo "to print current shell:"$(uname) echo
" "
echo "to print home directory:"$HOMEecho "
"
echo "to print os type:"$(uname) echo "
"
echo "current path setting:"$PATH
Output:-
RESULT:
ALGORITHM:
Shell script:
echo " Pipe Symbol Connect one or more
process"ls -1 *.sh | wc -l
echo "Redirect the output"
echo " "
echo "Redirect correct output to
newfile"sh job1.sh > correctoutput
echo " "
Output:
RESULT:
AIM:
To script for displaying current date, username, file listing and directoriesby getting
user choice.
ALGORITHM:
Step 1:Start the process Step 2:Use PS3 to enter the
string that displayed atconsole
Step 3:Use select and case comment to enter yourchoice and display it
Step 4:Use $(date) comment to display the date in option 1
Step 5:Use $(whoami) to printthe current user
Step 6:Use $(ls) to display filesand directories
Step 7:Stop the process.
Shell script:
#!/bin/bash
Output:
RESULT:
Aim:
To script to implement the filter command.
Algorithm:
Step 1: Start the process.
Step 2: Using touch file create two files as see.txt and dee2.txt Step 3:
Enter the content into the files by using echo command .
Step 4: Use the filter command grep-n to display lines that match specifiedpattern.
Step 5: Use the command grep-o to display the no.of lines that match thepattern.
Step 6: Use the filter command grep-v to display the lines that do not match thespecified
pattern.
Step 7: Use wc command to count the word lines and characters.Step 8:
Stop the process.
Shell script:-
touch dee.txt.deel.txt
echo "hello
good morning
how are you
?"> dee.txt
echo "one two three four five alpha
beta gamma delta epsilon">
deel.txt
echo "filter commands"
echo " "
echo "display the lines that match the specified pattern"grep -n
"good" dee.txt
echo " "
echo "display the number of lines that match the pattern"grep -c
"good" dee.txt
echo " "
echo "display the lines that do not match the pattern"grep -v
"good" dee.txt
echo " "
echo "count of words,lines and character "wc
dee.txt
echo " "
echo "to extract a column" cut -f
2-4 deel.txt
cut -c 6 deel.txt
echo " "
echo "display the contents of file"cat
dee.txt
echo " "
echo "display in uppercase"
tr "[:lower:]""[:upper:]"< dee.txtecho "
"
Output:
RESULT:
Aim:
To implement the file has which has 0 bytes.
Algorithm :
Shell script:-
Output:-
RESULT:
Algorithm :
shell script:-
RESULT:
script to find the greatest among the given set of number using command line
argument:
Aim :
Algorithm :
Shell script:-
small=${nos[$i]}
elif [ ${nos[$i]} -gt $greatest ];
then
greatest=${nos[$i
]}fi
done
echo "smallest number of array is $small"
echo "greatest number of array is $greatest"
Output:
RESULT:
Aim:
To check the given string is a palindrome or not.
Algorithm:
RESULT:
Algorithm:
Shell script:
echo "enter a
number"read n
echo "enter the number of multiples"
for((i=1;i<=10;i++))
do
echo "$n*$i = `expr $n \* $i`"
done
Output:
RESULT: