0% found this document useful (0 votes)
11 views33 pages

Linux Record

The document is a practical record for students in the Department of Computer Science at IFT-TEA College of Knitwear Fashion, detailing various shell scripting exercises conducted during the 2020-2021 academic year. It includes scripts for file commands, system configuration, pipes, redirection, filter commands, and more, each with a specific aim and algorithm. The document certifies the completion of these exercises and is intended for practical examination purposes.

Uploaded by

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

Linux Record

The document is a practical record for students in the Department of Computer Science at IFT-TEA College of Knitwear Fashion, detailing various shell scripting exercises conducted during the 2020-2021 academic year. It includes scripts for file commands, system configuration, pipes, redirection, filter commands, and more, each with a specific aim and algorithm. The document certifies the completion of these exercises and is intended for practical examination purposes.

Uploaded by

Pradeep Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
IFT-TEA COLLEGE OF KNITWEAR FASHION (Promoted by Tirupur Exporter’s Association) Affiliated to Bharathiar University e ® PRACTICAL RECORD NAME REGNO = DEPARTMENT OF COMPUTER SCIENCE, CORE LAB 5: LINUX AND SHELL PROGRAMMING LAB NIFT-TEA COLLEGE OF KNITWEAR FASHION Affiliated to Bharathiar University j (Promoted by Tirupur Exporter’s Association) Tirupur — 641 606 . NAME COURSE [Link] SEMESTER SUBJECT ‘This is to certified that this is s bonafide record of work done by the above student in the Computer Laboratory during the year 2020-2021. Staff Head of the Department ‘Submitted for the Practical Examination held on Internal Examiner External Examiner INDEX [Link]| DATE CONTEN [Link] | SIGN Ts 1 | 25.02.2021 | File Commands 2 | 25.02.2021 | system Configuration Details 3 | 26.02.2021 | Pipes, Redirection & tee Commands 4 | 26.02.2021 | Display details by getting user choice 5 | 04.03.2021 | Filter Commands 6 | 04.03.2021 | Remove The Files 7 | 05.03.2021 | Sum of the individual Digits 8 | 05.03.2021 | Find the Greatest Number 9 | 18.03.2021 | Palindrome 10 | 19.03.2021 | Multiplication Table [Link]:l 25.02.21 AIM: To write a shell script to stimulate the file command: rm, ep, cat, mv, emp, we, split, diff, ALGORITH STEP 1: Start the program, STEP 2: Open command prompt. STEP 3: Type the commands for rm, ep, cat, my, split, diff as given below. m= cp cat m - emp - split ditt - STEP 4: Stop the program removing files copying files concatenate files, moving files compare files splitting files differentiation between the files [student @localhost ~]$ eat> [Link] Hi Hello {studemt@localhost ~]$ 1s Desktop sample xt [student@localhost ~J8 ep [Link] [Link] {studem@localhost ~J$ s Desktop sample st [Link] {studemt@localhost ~J$ eat [Link] Hi Hello {student@localhost~]$_ eat >> [Link] Welcome to Linux programming {student @localhost ~]S eat [Link] Hi Hello Weleome to Linux programming [student@localhost ~]$_we [Link] 3.6.38 [Link] {student localhost] dif [Link] [Link] 23 >Weleome our linux lab [student@localhost ~]S emp [Link] [Link] Cmp : EOF on sample txt [student @localhost ~]$ mv [Link] [Link] [student @localhost ~}8 1s estxt Desktop [student@localhost ~]S rm [Link] [student @localhost ~]S bs estat Desktop [student @localhost ~]S split-b 10 estxt {student @locathost ~}8 ts estat Desktop xaa xab xae xad {[student@localhost ~] $ cat Mi hello ‘(student @localhost ~]S RESULT: “Thus the shell script has been successfully executed, Ex.No2d 25.02.21 SYSTEM CONFIGURATION AIM: ‘To write a shell script to show the system configuration such as currently logged user and his log name, current shell, home directory, os type, current path setting, current working directory, number of logged users, available shells, CPU information and memory information. ALGORITHM STEP 1: Open vi editor. STEP 2: Enter the “who | we -I” command to know the username STEP 3: To know the current shell enters the “$SHELL” command. STEP 4: To know the os type of our system enters the “SOSTYPE” command STEP To know the path enters the “$PATH” command. STEP 6: To know the current directory enter “$PWD” command, STEP 7: To know the cpu information enter “S(Isepu)” command. STEP 8: To list out the files using the Is command and to know memory information enter the $(free -m) command, STEP 9: Save and quit the program. #fbin/bash, nouserwho | we echo "user name $USER(login name:$LOGNAME)" echo "current shell: $SHELL" echo "home directory: HOME" echo "your os type:$OSTYPE" echo "current directory: $PWD" echo "currently logged: $(who -4)" echo "available shells: $(more /ete/shells)" echo "cpu informations: $(Isepu)" echo " memory information:$(free -m)" OUTPUT: Thus the shell script has been successfully executed, PIPES, REDIRECTION & TEE COMMANDS To write a shell script to implement the pipes, redirection and tee commands. ALGORITHM: STEP 1: Open vi editor with the file name STEP : Use #!/bin/bash to initializes the bash shell STEP 3: Display the number of files& directories by using the appropriate command and also display the contents of the file STEP 4: Display the files of the current directory by using “Is > temple” STEP 5: Then Redirecting error message to the file by using ‘cat abe2> errmsg" STEP 6: Close the vi editor and run the program in prompt. #bin/bash echo -e "The number of files& directories “Ishwe -Itee count xt" echo -e "The content of the file count “cat count txt” echo -e "The files of the content directory ‘Is > tempfile" echo " cat tempfile’™™ echo " cat 0 [Link]™* echo -¢ "Redirecting error message to file ‘eat abc2> errmsg" echo -e "The content of error file ‘cat errmsg” OUTPUT: $ raeraet content of the ae eee a Pra r Host eC oe eee Owens urea eae? studenta: RESULT Thus the shel script has been successfully executed, DISPLAY DETAILS BY GETTING USER CHOICE, ‘To write a shell script for displaying current date, user name, file listing and directories by getting user choices ALGORITHM: STEP 1: Open the vi editor. STEP : Start with “#!/bin/bash” command to run the program bash shell STEP 3: Using echo command print login name by using SLOGNAME command, STEP 4: To print the date, enter the “date” command. STEP 5: To print the current directory’s name enter the $PWD command. STEP 6: Get one directory name from the user by using read command, STEP 7: List out the files using the Is command to the entered directory, #fbin/bash, echo "hello, SLOGNAME" echo "current date is "date" echo "user is: ‘whoami"” echo "current directory‘$PWD" echo "ENTER THE NAME OF A DIRECTORY." read dir Is SHOME/Sdir OUTPUT: Thus the shell script has been successfully executed, [Link]:s aati FILTER COMMANDS ‘To write a shell script to implement the filter commands, ALGORITHM: STEP 1: Open the vi editor STEP 2: Start with “#!/bin/bash” command to run the program bash shell. STEP 3: Display the total number of files and directories in the current directory STEP 4: By using input redirection get the contents for ‘friend’ file and display the contents of the file STEP 5: By using sort command, sort the contents in a friend file and change their ease by tr Filter command STEP 6: After sorting the file implement the cat filter too, STEP 7: Save and quit the program. #Ufbin/bash. echo -e "The total number of files and directory is'S(Isiwe -I) " echo "§( cat > friends )" echo "content of friend fil’ echo "$(cat friends)" echo "sorting files" “sort < friendsitr "fa-z]" "[A-Z]" > FRIENDS echo "sorting and implement tr filter in the friends” echo "S(cat FRIENDS)" OUTPUT: File Edit Tabs Help pore eet ee filter in the fri Thus the shell seript has been successfully executed. [Link] iia REMOVING THE FILE, AIM: To write a shell seript to remove the files which have fie size as zero byte. ALGO! HM: STEP 1: Open the vi editor. STEP 2: Check all the files in the current directory whether it has content in it or not, STEP 3: If it has zero bytes then remove the file otherwise print the list of the files in the directory STEP 4: Save and quit the program #! bin/bash # echo "enter the filename" read fname if [-s $tname } then echo "$fname file size is not zero bytes” echo "the details of files are” 1s-1$fname else echo "$tname file size is zero bytes" rm -rf $fname echo "$fname file size is successfully removed” fi OUTPUT: enter the filename tom tom file size is not zero bytes the details of files are -rw-t--t~ 1 elcot elcot 43 Apr 5 11:31 tom enter the filename tom2 tom? file size is zero bytes tom2 file is successfully removed SUM OF THE INDIVIDUAL DIGITS To write a shell script to find the sum of individual digits ofa given number ALGORITHM: STEP 1: Open the vi editor with the filename, STEP : Start with “#Y/bin/bash” to initialize the bash shell STEP 3: Get the number by using a read command. STEP 4: Initialize a sum=0 and refer nas “a=Sn” . STEP 5: To check the condition by using do while [Sn -gt 0}. STEP 6: To perform a arithmetic operation using sum= $((sum*x)), STEP 7: Print the sum of individual digits for given number. STEP 8: Save and quit the program. #1/bin/bash ‘echo "ENTER NUMBER" read n sum=0 a-$n while [ $n -gt 0}, do x=$((n%10)) sum=$((sum+x)) n=S((n/10)) done echo "THE SUM OF THE INDIVIDUAL DIGIT Sa is‘$sum" OUTPUT: RESULT: “Thus the shell seript has been successfully executed. ExNo:’ ett FIND THE GREATEST NUMBER AIM ‘To write a shell script to find the greatest among the given set of number using, command line arguments. ALGORITHM: STEP 1: Open vi editor start to write the script with #1/bin/bash shell STEP 2: To reference a big =$land check the condition by using a if[ $i -gt Sbig} STEP 3: If the condition is true then print the largest number by using the commands “big=Si" STEP 4: Finally print the largest number. STEP 5: Save and quit the program. #1/bin/bash ‘echo "ENTER NUMI" read num! echo "ENTER NUM2" read num2 echo "ENTER NUM3" read num3 ‘echo "ENTER NUM4" read num4 if [ Snuml -gt $num2 ] && [ $num! -gt $num3 J && [ Snum1 -gt $um4 } then ‘echo Snum1 lif [ $num? -gt Srum! ] && [ Sum? -gt $num3 ] && [ $num? -gt Snum4 ] then ‘echo Snum2 else echo Snum3 fi ourur: “Thus the shell script has been successfully executed. PALINDROME CHECKING ‘To write a shell seript to check whether the given string is palindrome or not, ALGORITHM: STEP 1: Open vi editor with the file name STEP 2: Use “#!/bin/bash” to initialize the bash shell STEP 3: Get the string by using read command STEP 4: Reverse the string by using str [rev STEP 5: Compare both the string file i STEP 6: If tis not equal, print “It is not a palindrome STEP 7: Save and quit the program. is equal print “The given string is palindrome” #\/bin/bash ‘echo "ENTER THE STRING.” read strl str2=$(echo "Sstrl"[rev) if[ "SstrI" == "$str2" ] ; then echo "GIVEN STRING IS A PALINDROME" else echo "GIVEN STRING IS NOT A PALINDROME" fi OUTPUT: ‘RESULT: ‘Thus the shell script has been successfully executed. MULTIPLICATION TABLE, AIM: ‘To write a shell script to print the multiplication table of the given argument using “for” loop, ALGORITHM: STEP 1: Open the vi editor. STEP 2: Use “#!/bin/bash” to initialize the bash shell STEP 3: To get number by using read number. STEP 4: Use for loop to print multiplication table for the given number. STEP 5: Save and quit the program. ‘#\/bin/bash echo "Enter a number" read n echo "$n * $i= expr Sn\" $i" expr $i+ 1 done OUTPUT: ‘RESULT: ‘Thus the shell seript has becn successfully executed.

You might also like