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

Linex Lab Notes

Linux lab notes bharathiar University
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
41 views

Linex Lab Notes

Linux lab notes bharathiar University
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 32
ex-no: | pate : 18-023 BASIC LINUX comMMANDS ane Te waite a shell script to stimutoke the ile commands aay: ALGORITHM * FM ep, car, rev ,emp, We, Splits Step? Starr the process - Stepo: In tne terminal type “the fotlowing eoromancls Step 3: Type the tm command -to rerneve porticitar | tite jeutar tite bo Step 4’ Type “the cp command to cwpy a pariaular another ile Step ©: Type the car cormmand to display or to | ven the mentitned ile | otep&! Type the mv command t> -move the Hle location “to another tocakfon - dtep n Type bhe cmp command +0 Compare two dittrenr tiles Step 8: Type the We comrandt\ ceunt the number Of tines tna trle. Step 4: Type the. splitvana ditt deramand te eplit | erence between tiles respectively, Step 10: Stop the process, CODING CREATING A FILE ; [srowesug2@linuxserver ~]$ cat > File This is a file. REMOVING FILE. [srewesug2@linuxserver ~]$ rm File [srowesug2@linuxserver ~]$ cat File cat: File: No such file or directory COPYING FILES : [srewesug2@linuxserver ~]$ ep linux program [srowesug2@linuxserver ~]$ cat program linux is very easy language MOVING OR RENAMING FILES : [srowesug2@linuxserver ~]S my example sample [srowesug2@linuxserver ~]S cat sample Itis an example program COMPARING FILES : [srewesug2@linuxserver ~]$ cmp linux program linux program differ: byte 1, line 1 WORD COUNT : [srewesug2@linuxserver ~]$ we program 1 417 program SPLITTING FILES : [srowesug2@linuxserver ~]$ split -1200 program [srewesug2@linuxserver ~]$ Is files linux sample program xaa (sowwangsetinmaserver JS split a7 program [semesngtinanserer <]8 ts es Trax sample srw gaa xa aa {sewesug2 Slimanserver JS split at program [srewesng2 Dlinuxseryer ~]s Is Ales Trae sample program x00 saa xanaanga ING FILES: linuxserver ~]$ ditt program linux, isan example > Tinuy is very easy language RESULT: “7 The above program was successfully exept AND SYSTEM INADEMATION ComMAN DS a helt script to display the system ALGORITHM: Step tt Start the process Step 2: Type the wWhoami esmmand to check ‘the eaged user and Leg name pS: Use echo "¥ shen" command to Know the current Shell Stept: Use Cd esmmand +p move to the home Airectory Step 5: Use Car /etc/as— release command to vier! cthe astype jnpormation. Step 6 Use echo “$paTH” command to know the current parn Sertir Step tT! Use pwd commant to Fnow the current Works directory Step 8: Te know: the currently ed umber of ters use wehe command. Step 3: Te view the available Shells use chsh . Step Io: Te show cpu Togorma tfon. use cat/preeepeingo command Step Wr Te Show memory Tnpormation use cat] proc / “™memints command . Step ia: Stop the process. CODING CURRENT LOGIN: [seewesng? @ilinuxserver ~J$ whoami srewesug2 CURRENT [srewesug2@linuxserver ~]$ echo "§SHELL" /bin/bash HOME DIRECTORY : [srewesug2@linuxserver ~]$ ~ -bash: /home/srewesug2: Is a directory INFORMATION ABOUT OPERATING SYSTEM : TRFORMATION ABOUT OPERATING SYSTEM. [srewesug2@linuxserver ~]$ uname -a Linux linuxserver 4.13.9-300.fe27.x86_64 #1 SMP Mon Oct’S 1: x86_64 x86_64 GNU/Linux [srewesug2@linuxserver ~]S uname Linux CURRENT PATH : [srewesug2@linuxserver ~]$ echo "$PATH" /ust/local/bin:/ust/bin:/usr/local/sbin:/ust/sbin PRESENT WORKING DIRECTORY : [stewesug2@linuxserver ~]$ pwd shomelsrewesug? :41:58 UTC 2017 x86_64 CURRENT LOG: u {srewestg? @linuxserver ~]S w 3 up 1 day, 1:22, 14 users, load average: 0.16, 0.48, 0.29 JSER TTY LOGIN@ IDLE JCPU PCPU WHAT srewesug pts/2 00:10 57.00s 0.07s 0.075 -bash srowesug pts/3. 00:27 4.00s 0.06 0.03s vi anandhi srowesug pts/4 00:34 41.00s 0.03s 0.01 vi apple srewesug pts/5 00:11 8.00s 0.06s 0.02s vi student choice SHOW ALL AVAILABLE SHELL! {srowesug2@linuxserver ~]$ chsh -1 Poin/sh Jein/bash, Jsbin/nologin Jusr/bin/sh Just/bin/bash Jusr/sbin/nologin DISPLAY CPU INFORMATION : [srewesug2@linuxserver ~]$ cat /proc/epuinfo processor 0 vendor_id : Genuinelntel cpufamily :6 model 730 modelname — : Intel(R) Xeon(R) CPU X3430 @2.40GHz stepping microcode: 0x7 cpuMHz — ; 240.005 cache size: 8192 KB coeid 30 qquceres 4 apicid ° joitial apicid 0 fp yes fpa_cxeeption ; yes cpuidlevel 311 wp DISPLAY MEMORY INFORMATION : [srewesug2@linuxserver ~]$ cat /proc/meminfo MemTotal: 4002940 kB MemFree: 3161976 kB MemAvailable: 3415808 kB Buffers: 4296 kB Cached: 433992 kB Active: 279928 kB Inactive: 358164 Kb [srewesug2@linuxserver ~]8 free -m total used free shared bufi/eache available Mem: 3909 296-3087 1 524 3335 Swap: 4035 0 4035 [srewesug2@linuxserver ~]$ RESULT: The above program was succe; 15 ex-no:3 IMPLEMENTING: = pipes Pate? 25.0723 ss > REDIRECTION AND TEE commpNins AIM! ~ Te MATES Shells sexipe te implement the “potlennng Oh PIPCS 5 Redirection and Tee commands ALEIORITHNL: Step ti Start -the Precess Step2: Pipe symbot (1) is used to connect one or more process Step 8: Redirection cormmand (>>) usel to transler ‘the pile from one pant ints ansther. | Step 4: Use Tee command to eppy a data dom | Standard input te each +ile salso te standard | cutpur - | Step: Displasy the result on the screen | Step &: Save the potbcess | Step 7! Stop the process. CODING PIPES COMMAND : [srowesug23@linuxserver ~]$ cat >cars Audi benz skoda Jaguar Ferrari Compine 2 OF MOLE Cemmendy [srewesug23@linuxserver ~I$ cat cars {grep skoda skoda [srewesug23@linuxserver ~]$ cat cars | grep fe bets tepper cous anal benz sonler cas & Ferrari [srowesug23@linuxserver ~J$ cat cars | grep -fe> count oh mateliing lines 2 [srowcsug23@linuxserver ~]$ cat cars | grep -na a.skoda Ls matching Woes pytnarmber 4.Jaguar 5.Ferrari [srewesug23@linuxserver ~]§ cat cars| sort-r > sieveiSe Sorting Ferrari Jaguar skoda benz Isrewesug23@linuxs€fver ~]$ cat cars| sort-n 7?) A.Jaguar 5 Ferrari [srowesug23@linuxserver Audi benz ~I8 cat cars| more skoda ~more— [srowesug23@linuxserver Audi ~IS cat cars [less benz skoda Jaguar (END) TEE COMMAND : [srewesug23@linuxserver ~]$ cat >fruits apple banana 4 orange kiwi strawberry [srowcsug23@linuxserver ~]$ Saeveanspie [srewcsug23@linuxserver ~I$ cat fruits | tee vegetables apple banana orange 20 ai pea ner” N COMMAND : linuxserver ~]$ cat > carnivore pepinecTio 23a {snes Tiger Frog xserver ~]$ cat >herbivore Elephant Monkey Horse Rabbit [grewesug23@linuxserver ~]$ cat carnivore herbivore > animals [srowesug28@linuxserver ~]$ cat animals Tiger Frog Lion Elephant Monkey Horse Rabbit RESULT ‘The aboy e pro. Program has been successfully executed ee wy step. Using case Stakement, and case csmmand. Sigps: By giving opie |, then athe arent data Wi Be disploued onthe screen. delare a caso Variables 5. T+ the choice fs 3, then the let opatile | ond directions will Be Aisptaned Sep+: Tt one Dp the cheice_ toet stinally detoulk ease ger execuked. Step 7: Step the proceés CODING psde"Entor your choico:" options=(optiont "optiona” » select op in "S{options[@)}" ‘optiong « do case Sop in “option1") echo "Today is" “date* *option2") echo "Current user" ‘whoami* “option3") echo "Listing" “Is* “quit") break *Jecho "INVALID CHOICE" esac Done ‘quit’ | \ | gutPuT qeqnes ope eiinurrsenver fs IS sh 4displaypro, ch option! py option? 43) option ayquit gi today is a2 hu Mar 30 01:48:45 EDT 2023 current user srewesug23 273 ro.sh 10.sh 1shell 2 "sh 8prog.sh 9} q 2shell Ska pro.sh abe aban waa ta ish adapta sh allout, 7pr0gte alphabets arraysize.sh bike bikes bi colors bikes bird birds Ree car car? care Gee yah al gram sh ‘at choice. phabet -Sh class4, colo Listing 1 100) ramsum. color.sh #7 INVALID CHOICE 24 ferewesug23@linuxserver ~IS a RESULT The abo ve program has executed successfully. 0:5 wn pores 9 O% “HaPLerte ny b i AN TS vivite hy - eM 2 - yilker fora, © 4 implement he Algerittun : sep ' Store Ane Proce: step 2. Use OTP Command | , Bors moa +e. 0 WSONER partite step 3’. Use Sore | P command i. Ofarge o pees tm a Screen, a id - | | st We a ep 4 Srmimantht in Check the Hod. | - | | step &: Use Pipe command te ermbine process Kit another anc menu eommand oe. dete - ~ infomation on forward Step, Stop the prog Ee Screen. } CODING [srowesun23@linuxserver ~I$ cat s color green 11 yellow -12 red -13 blue-14 purple -15 [srewesug?3@linuxserver ~]§ cat colors green -11 yellow -12 red-13 blue -14 purple -15 [srowesug23@linuxserver ~]$ cat 1.green-11 “colors 2yellow -12 3ured-13, A.blue-14 5. purple-15 [srowcsug23@linuxserver Scolors [srowesug23@linuxserver ~]$ we 5 colors [srewcsug23@linuxserver ~I$ we 24 colors [srcwesug23@linuxserv green yellow I$ we -I colors -w colors -c colors [srowesug23@linuxserver ~I$ cat c blue Purple ‘er ~]$ cat colors | hea; We C-eptferns] Cpatny We Ss wordcoun & We =) Color ~1 > NO of Lines —W ano S{worels - C2 no ol charter 3) teresa ~1S cut yellow red plue purple lense ~18 cut " -¢--f2 colors 13 14 15 ferowesug23@linuxserver ~I$ RESULT The above progra m was successfully executed, vy, 35 ob s . ne RI MOVING FILES HAs yepp pyres Te wite a shett Scripe to remeve The files wn ‘fas the file size as zorg. yr : ered ain Ae! M . Store te process ger! - , Use clear command ep 2 to clear the area, pepo ne eommand fs used pe display the contnt sop Use ‘the read command to gee the filename tor the sep 5: Use the i Stotement to pertorm and te chech TE the givon yitename exists or -no user. stepb: Then T& checks ie given tile fs empty or ull gtep 1 Stepg, St™p “ine process a fi command te the Cf statemene codING | go ENTERANY FILE NAME" esi byes esyes! na asso bytes ‘FILE EXIST” g[-sSoytes] tan acho Sbytes "FILE HAS SIZE>0" mmSbytes echo Sbytes "FILE HAS DELETED WHICH HAS SIZE=0" =I alse echo ‘FILE DOESN'T EXIST" quiput call NY FILE NAME: sums.sh yaq@linuxserver ~J]$ sh Gprogram.sh pteR A FILE E IST. ILE HAS DELETED WHICH HAS SIZE=0 \g23@linuxserver ~|s sows \g23@linuxserver ~]$ sh 6program.sh ENTER ANY FILE NAME: RRR FILE DOESNT EXIST igrowosug23@linuxserver ~js [growesug23@linuxserver ~]$ sh 6program.sh ENTER ANY FILE NAME:pro.sh prosh FILE EXIST pro.sh FILE HAS SIZE>0 [srowesug23@linuxserver ~|s it 7 ino! & 60M OF ne IND) el? ws ERY DUAL Diets AM ; 7 To write a shen of Individuar digits Program to tind the gure | ORITHM iy psorrren step pr Stare the pro lep 2° The read command is useg wget a number ror the. user gep 3° Read the standom | ; gum - 7 in step: USING “ sum OF individual digits - Sep 7 The added result will Be | the Neche 7 command number +o find the e do-nhile levp, coleulate a pained using Step. Save ‘tne process ‘step SEP tne P - a CODING echo -d “Enter number :" read d sd=0 sum=0 while [$d -at 0] do sd=$(($d % 10)) d=$(($d / 10)) sum=$(($sum+$sd)) done echo "Sum of all digit is Ssum" output jarcnesu923@liNUXSEIVer ~IS sh prog? gh Enter the number:777 sum of all digit is 21 {srewesug23@linuxserver ~l$ ia RESULT The above program has executed successfully. Step &: Step et B and 0 iS Jarmer than Ban Zr On, T or 2 +. 3 give sroberrere te display the resus py coviNG echo venter Num * , cea mt echo "Enter Numa" read num2 echo “enter Num : read num3 ie[gnum “4 [ gt Snum2] &&[ Snum1 ~gt $num: 3] then an ea number is : gt Snum1 ] && [ eu um 2 ~ ‘gt Snum! 3] then echo “The gre me greatest number is : $| :Snum2" echo -e" $The greate: gl st number is: Snum: 3" “\ utruT a @UNUxXBerVer —]S ow ‘ YS Sh peanut x ral OF or NUN? ee Nums we area st 02 gq@linuxserver ~|$ RESULT The above program has executed s uecessfully. -no4 PALINDROME waite To QA Shel} setipe programs +o 2. yind.rome a command 4° P argurnents, pp crOR THO Sep 1, Stare the prouss step 2" Read command used to ger a inpuk 4qrom tne user ! grep 3: Use the “rev” to reverse the string in the variable evorse and store step + Use de lovp to calculate reverse suumber check the grees covins ech sy Enter the number.” ead «0 eve oneS¥ rite [SY 801 do d-$(($y%10)) y2(Sy/ 0)) eveg(echo S{rev}S{sd} ) done if[ $on-eq Srev J; then echo "Number is palindrome” else echo “Number is not a palindrome" e fi ure gn 3@imesenrer JS sh oj 9pro.sh ee eno umber 25? soe is palindrome ae As shoi opro.sh not @patindrome aber i 1923@! inuxserver ~]$ ferowes RESULT le above ve program has e) sfi is executed succe . S! To woite a ghett Seripe to prink mult plicatt on able to the geen osgurnents dj ALgok TAM step start the process sep 2! Read esommand is used +0 qe a. Inpuk& rom the uset : step 3: “Ther by using for command te catentate a -pumber tnultf plied ey giver -rumber - Use eths command With express sep 4! command with express command +0 9er tune ourpur - step o: Wnile store wien ond ae do and done feynords Ste, , P ae Soave the process Step 1: stop the pr CODING cals multilable.gh echo °e "Enter the tables read o for fin} 2345678910 do echo "So * $f = $((oAf))" sleep 1 done OUTPUT [srcwcsug23@linuxserver ~]$ sh username.sh Enter the table: 7 7127 72214 7*3=21 74228 7*5=35 7*10=70 [srcwesug23@linuxserver ~]$ RESULT The above program has executed successfully.

You might also like