From d1e45e0291c2838d5708e6ea79eed8df7f2e57f1 Mon Sep 17 00:00:00 2001 From: sarishvarshan <152167665+sarishvarshan@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:06:07 +0530 Subject: [PATCH] Update README.md --- README.md | 674 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 496 insertions(+), 178 deletions(-) diff --git a/README.md b/README.md index 7feb9218..4c5c0f28 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ + # OS-Linux-commands-Shell-scripting Operating systems Lab exercise # Linux commands-Shell scripting @@ -42,25 +43,53 @@ s.n. dasgupta ### Display the content of the files cat < file1 ## OUTPUT - - - +``` +chanchal singhvi +c.k.shukla +s.n.dasgupta +sumit chakrobart +^d +``` cat < file2 ## OUTPUT - - +``` +anil aggarwal +barun sengupta +c.k.shukla +lalit chowdury +s.n.dasgupta +^d +``` # Comparing Files cmp file1 file2 ## OUTPUT - + file1 file2 differ: char 1, line 1 comm file1 file2 ## OUTPUT - - + ``` +anil aggarwal + barun sengupta + c.k.shukla +chanchal singhvi +c.k.shukla + lalit chowdury + s.n.dasgupta +sumit chakrobarty + ``` diff file1 file2 ## OUTPUT - - +``` +--- file1 ++++ file2 +@@ -1,4 +1,5 @@ +-chanchal sindhvi ++anil aggarwal ++barun sengupta + c.k.shukla ++lalit chowdury + s.n.dasgupta +-sumit chakrobarty +``` #Filters ### Create the following files file11, file22 as follows: @@ -82,19 +111,27 @@ cat > file22 cut -c1-3 file11 ## OUTPUT - - +``` +Hel +Thi +``` cut -d "|" -f 1 file22 ## OUTPUT - - +``` +1001 +1002 +1003 +``` cut -d "|" -f 2 file22 ## OUTPUT - - +``` +Ram +tom +Joe +``` cat < newfile ``` Hello world @@ -102,46 +139,48 @@ hello world ^d ```` cat > newfile +``` Hello world hello world - + ``` grep Hello newfile ## OUTPUT - - +``` +Hello world +``` grep hello newfile ## OUTPUT - - - +``` +hello world +``` grep -v hello newfile ## OUTPUT - - +``` +Hello world +``` cat newfile | grep -i "hello" ## OUTPUT - - +``` +Hello world +hello world +``` cat newfile | grep -i -c "hello" ## OUTPUT - - - - -grep -R ubuntu /etc -## OUTPUT - - +``` +2 +``` grep -w -n world newfile ## OUTPUT - - +``` +1:Hello world +2:hello world +``` cat < newfile ``` Hello world @@ -163,61 +202,83 @@ Linux is best in this World ``` egrep -w 'Hello|hello' newfile ## OUTPUT - - +``` +Hello world +hello world +``` egrep -w '(H|h)ello' newfile ## OUTPUT - - +``` +Hello world +hello world +``` egrep -w '(H|h)ell[a-z]' newfile ## OUTPUT - - +``` +Hello world +hello world +``` egrep '(^hello)' newfile ## OUTPUT - - +``` +hello world +``` egrep '(world$)' newfile ## OUTPUT - - +``` +Hello world +hello world +``` egrep '(World$)' newfile ## OUTPUT - - +``` +Linux is best in this World +``` egrep '((W|w)orld$)' newfile ## OUTPUT - - +``` +Hello world +hello world +Linux is best in this World +``` egrep '[1-9]' newfile ## OUTPUT - - +``` +Linus is world number 1 +``` egrep 'Linux.*world' newfile ## OUTPUT - +``` +Linus is world number 1 +``` egrep 'Linux.*World' newfile ## OUTPUT - - +``` +Linux is best in this World +``` egrep l{2} newfile ## OUTPUT - - +``` +Hello world +hello world +``` egrep 's{1,2}' newfile ## OUTPUT - - +``` +Linus is world number 1 +Unix is predecessor +Linux is best in this World +``` cat > file23 ``` 1001 | Ram | 10000 | HR @@ -234,81 +295,148 @@ cat > file23 sed -n -e '3p' file23 ## OUTPUT - - +``` +1002 | tom | 5000 | Admin +``` sed -n -e '$p' file23 ## OUTPUT - - +``` +1001 | Ram | 10000 | HR +``` sed -e 's/Ram/Sita/' file23 ## OUTPUT - - +``` +1001 | Sita | 10000 | HR +1001 | Sita | 10000 | HR +1002 | tom | 5000 | Admin +1003 | Joe | 7000 | Developer +1005 | Sam | 5000 | HR +1004 | Sit | 7000 | Dev +1003 | Joe | 7000 | Developer +1001 | Sita | 10000 | HR +``` sed -e '2s/Ram/Sita/' file23 ## OUTPUT - - +``` +1001 | Ram | 10000 | HR +1001 | Sita | 10000 | HR +1002 | tom | 5000 | Admin +1003 | Joe | 7000 | Developer +1005 | Sam | 5000 | HR +1004 | Sit | 7000 | Dev +1003 | Joe | 7000 | Developer +1001 | Ram | 10000 | HR +``` sed '/tom/s/5000/6000/' file23 ## OUTPUT - - +``` +1001 | Ram | 10000 | HR +1001 | Ram | 10000 | HR +1002 | tom | 6000 | Admin +1003 | Joe | 7000 | Developer +1005 | Sam | 5000 | HR +1004 | Sit | 7000 | Dev +1003 | Joe | 7000 | Developer +1001 | Ram | 10000 | HR +``` sed -n -e '1,5p' file23 ## OUTPUT - - +``` +1001 | Ram | 10000 | HR +1001 | Ram | 10000 | HR +1002 | tom | 5000 | Admin +1003 | Joe | 7000 | Developer +1005 | Sam | 5000 | HR +``` sed -n -e '2,/Joe/p' file23 ## OUTPUT - - +``` +1001 | Ram | 10000 | HR +1002 | tom | 5000 | Admin +1003 | Joe | 7000 | Developer +``` sed -n -e '/tom/,/Joe/p' file23 ## OUTPUT - - +``` +1002 | tom | 5000 | Admin +1003 | Joe | 7000 | Developer +``` seq 10 ## OUTPUT - - +``` +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +``` seq 10 | sed -n '4,6p' ## OUTPUT - +``` +4 +5 +6 +``` seq 10 | sed -n '2,~4p' ## OUTPUT - - +``` +sed: no address after comma +``` seq 3 | sed '2a hello' ## OUTPUT - - +``` +1 +2 +hello +3 +``` seq 2 | sed '2i hello' ## OUTPUT - - +``` +1 +hello +2 +``` seq 10 | sed '2,9c hello' ## OUTPUT - - +``` +1 +hello +10 +``` sed -n '2,4{s/^/$/;p}' file23 ## OUTPUT - - +``` +$1001 | Ram | 10000 | HR +$1002 | tom | 5000 | Admin +$1003 | Joe | 7000 | Developer +``` sed -n '2,4{s/$/*/;p}' file23 - - +``` +1001 | Ram | 10000 | HR* +1002 | tom | 5000 | Admin* +1003 | Joe | 7000 | Developer* +``` #Sorting File content cat > file21 ``` @@ -320,8 +448,13 @@ cat > file21 ``` sort file21 ## OUTPUT - - +``` +1001 | Ram | 10000 | HR +1002 | tom | 5000 | Admin +1003 | Joe | 7000 | Developer +1004 | Sit | 7000 | Dev +1005 | Sam | 5000 | HR +``` cat > file22 ``` 1001 | Ram | 10000 | HR @@ -333,14 +466,28 @@ cat > file22 ``` uniq file22 ## OUTPUT - - +``` +1001 | Ram | 10000 | HR +1002 | tom | 5000 | Admin +1003 | Joe | 7000 | Developer +1005 | Sam | 5000 | HR +1004 | Sit | 7000 | Dev +``` #Using tr command cat file23 | tr [:lower:] [:upper:] ## OUTPUT - + ``` +1001 | RAM | 10000 | HR +1001 | RAM | 10000 | HR +1002 | TOM | 5000 | ADMIN +1003 | JOE | 7000 | DEVELOPER +1005 | SAM | 5000 | HR +1004 | SIT | 7000 | DEV +1003 | JOE | 7000 | DEVELOPER +1001 | RAM | 10000 | HR +``` cat < urllist.txt ``` www. yahoo. com @@ -356,39 +503,67 @@ www. mrcet.... com ``` cat urllist.txt | tr -d ' ' ## OUTPUT - - + ``` +www.yahoo.com +www.google.com +www.mrcet....com +``` cat urllist.txt | tr -d ' ' | tr -s '.' ## OUTPUT - - +``` +www.yahoo.com +www.google.com +www.mrcet.com +``` #Backup commands tar -cvf backup.tar * ## OUTPUT - - +``` +bench.py +file21 +file22 +file23 +hello.c +hello.js +readme.txt +urllist.txt +``` mkdir backupdir mv backup.tar backupdir tar -tvf backup.tar ## OUTPUT - - -tar -xvf backup.tar +``` +-rw-r--r-- ezlian/ezlian 31 2024-02-09 16:02 file1 +-rw-r--r-- ezlian/ezlian 28 2024-02-09 16:11 file11 +-rw-r--r-- ezlian/ezlian 31 2024-02-09 16:06 file2 +-rw-r--r-- ezlian/ezlian 130 2024-02-16 16:24 file21 +-rw-r--r-- ezlian/ezlian 154 2024-02-16 16:25 file22 +-rw-r--r-- ezlian/ezlian 209 2024-02-16 15:39 file23 +-rw-r--r-- ezlian/ezlian 95 2024-02-15 09:44 newfile +-rw-r--r-- ezlian/ezlian 51 2024-02-22 09:09 urllist.txt +``` +tar -xvf backupdir/backup.tar ## OUTPUT - -gzip backup.tar - -ls .gz +``` +file1 +file11 +file2 +file21 +file22 +file23 +newfile +urllist.txt +``` +ls: .gz: ## OUTPUT - +``` +backup.tar.gz gunzip backup.tar.gz -## OUTPUT - - +``` # Shell Script ``` echo '#!/bin/sh' > my-script.sh @@ -397,8 +572,9 @@ echo 'echo Hello World‘; exit 0 >> my-script.sh chmod 755 my-script.sh ./my-script.sh ## OUTPUT - - +``` +Hello World +``` cat << stop > herecheck.txt ``` hello in this world @@ -409,8 +585,11 @@ stop cat herecheck.txt ## OUTPUT - - +``` +hello in this world +i cant stop +for this non stop movement +``` cat < scriptest.sh ```bash \#!/bin/sh @@ -447,26 +626,37 @@ chmod 777 scriptest.sh ./scriptest.sh 1 2 3 ## OUTPUT - - +``` +File name is ./scriptest.sh + File name is scriptest.sh + First arg. is 1 + Second arg. is 2 + Third arg. is 3 + Fourth arg. is + The $@ is 1 2 3 + The $\# is $# + The $$ is 124 + ``` ls file1 ## OUTPUT - +``` +file1 +``` echo $? -## OUTPUT -./one -bash: ./one: Permission denied - +## OUTPUT +``` +0 +``` echo $? -## OUTPUT - +## OUTPUT +``` abcd - +``` echo $? - ## OUTPUT - - - +## OUTPUT +``` +1 +``` # mis-using string comparisons cat < strcomp.sh @@ -496,15 +686,22 @@ echo "$val1 is less than $val2" fi ``` ##OUTPUT - - - -chmod 755 strcomp.sh - +``` +val1=baseball + val2=hockey + if [ $val1 \> $val2 ] + then + echo "$val1 is greater than $val2" + else + echo "$val1 is less than $val2" + fi +``` +chmod 755 strcomp.sh ./strcomp.sh ## OUTPUT - - +``` +baseball is less than hockey +``` # check file ownership cat < psswdperm.sh ```bash @@ -530,7 +727,9 @@ fi ``` ./psswdperm.sh ## OUTPUT - +``` +You are the owner of the /etc/passwd file +``` # check if with file location cat>ifnested.sh ```bash @@ -576,9 +775,10 @@ fi ./ifnested.sh ## OUTPUT - - - +``` +/root The object exists, is it a file? + No,/root it is not a file! +``` # using numeric test comparisons cat > iftest.sh ```bash @@ -620,7 +820,10 @@ $ chmod 755 iftest.sh $ ./iftest.sh ##OUTPUT - +``` +“The test value 10 is greater than 5” + “The values are different” +``` # check if a file cat > ifnested.sh ```bash @@ -669,7 +872,10 @@ $ chmod 755 ifnested.sh $ ./ifnested.sh ##OUTPUT - +``` +“/root The object exists, is it a file?” + “No,/root it is not a file!” +``` # looking for a possible value using elif cat elifcheck.sh ```bash @@ -697,8 +903,15 @@ $ chmod 755 elifcheck.sh $ ./elifcheck.sh ## OUTPUT - - +``` +Welcome Ram + Please enjoy your visit + Welcome Rahim + Please enjoy your visit +Special testing account + gganesh, Do not forget to logout when you're done + Sorry, you are not allowed here +``` # testing compound comparisons cat> ifcompound.sh ```bash @@ -713,7 +926,9 @@ fi $ chmod 755 ifcompound.sh $ ./ifcompound.sh ## OUTPUT - +``` + The file exists and you can write to it +``` # using the case command cat >casecheck.sh ```bash @@ -732,7 +947,14 @@ esac $ chmod 755 casecheck.sh $ ./casecheck.sh - +##OUTPUT: +``` +Welcome Ram/Rahim + Please enjoy your visit + Special testing account + gganesh, Do not forget to logout when you're done + Sorry, you are not allowed here +``` cat > whiletest ```bash #!/bin/bash @@ -747,8 +969,19 @@ done $ chmod 755 whiletest.sh $ ./whiletest.sh - - +##OUTPUT: +``` +10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + ``` cat untiltest.sh ```bash \#using the until command @@ -760,9 +993,13 @@ var1=$[ $var1 - 25 ] done ``` $ chmod 755 untiltest.sh - - - +##OUTPUT +``` +100 + 75 + 50 + 25 +``` cat forin1.sh ```bash \#!/bin/bash @@ -774,8 +1011,16 @@ done ``` $ chmod 755 forin1.sh - - +$ ./forin1.sh +## OUTPUT +``` + The next state is Alabama + The next state is Alaska + The next state is Arizona + The next state is Arkansas + The next state is California + The next state is Colorado +``` cat forin2.sh ```bash \#!/bin/bash @@ -798,9 +1043,13 @@ echo “word:$test” done ``` $ chmod 755 forin2.sh - -$ ./forin2.sh - + $ ./forin2.sh +## OUTPUT +``` + word:I + word:dont know if thisll + word:work +``` cat forin3.sh ```bash \#!/bin/bash @@ -811,7 +1060,15 @@ echo "word:$test" done ``` $ ./forin3.sh - + ## OUTPUT + ``` + word:I + word:don't + word:know + word:if + word:this'll + word:work +``` cat forin1.sh ```bash #!/bin/bash @@ -824,6 +1081,14 @@ done $ chmod 755 forin1.sh ## OUTPUT +``` +word:I + word:don't + word:know + word:if + word:this'll + word:work +``` cat forinfile.sh ```bash #!/bin/bash @@ -836,6 +1101,7 @@ done ``` $ chmod 777 forinfile.sh $ cat cities +``` Hyderabad Alampur Basara @@ -843,10 +1109,18 @@ Warangal Adilabad Bhadrachalam Khammam +``` ## OUTPUT - - +``` + Visit beautiful Hyderabad + Visit beautiful Alampur + Visit beautiful Basara + Visit beautiful Warangal + Visit beautiful Adilabad + Visit beautiful Bhadrachalam + Visit beautiful Khammam +``` cat forctype.sh ```bash #!/bin/bash @@ -859,7 +1133,13 @@ done $ chmod 755 forctype.sh $ ./forctype.sh ## OUTPUT - +``` +The value of i is 1 + The value of i is 2 + The value of i is 3 + The value of i is 4 + The value of i is 5 +``` cat forctype1.sh ```bash #!/bin/bash @@ -890,8 +1170,13 @@ $ chmod 755 fornested1.sh $ ./fornested1.sh ## OUTPUT - - + ``` + 1 - 5 + 2 - 4 + 3 - 3 + 4 - 2 + 5 - 1 +``` cat forbreak.sh ```bash #!/bin/bash @@ -907,7 +1192,11 @@ done echo "The for loop is completed“ ``` ## OUTPUT - +``` +Iteration number: 1 + Iteration number: 2 + The for loop is completed +``` $ chmod 755 forbreak.sh $ ./forbreak.sh @@ -932,7 +1221,13 @@ $ chmod 755 forcontinue.sh $ ./forcontinue.sh ## OUTPUT - + ``` +Iteration number: 1 + Iteration number: 2 + Iteration number: 4 + Iteration number: 5 + The for loop is completed +``` cat exread.sh ```bash #!/bin/bash @@ -946,8 +1241,10 @@ $ chmod 755 exread.sh $ ./exread.sh ## OUTPUT - - +``` + Enter your name: John + Hello John, welcome to my program. +``` cat exread1.sh ```bash #!/bin/bash @@ -958,9 +1255,10 @@ echo "Hello $name, welcome to my program. “ $ chmod 755 exread1.sh ## OUTPUT - - - +``` +Enter your name: sanju + Hello sanju, welcome to my program. +``` $ ./exread1.sh cat funcex.sh @@ -979,11 +1277,11 @@ echo "Usage: badtest1 a b" fi ``` ## OUTPUT +$ bash script.sh 1 2 ./funcex.sh ./funcex.sh 1 2 - cat argshift.sh ```bash @@ -997,7 +1295,11 @@ $ chmod 777 argshift.sh ## OUTPUT $ ./argshift.sh 1 2 3 - +``` +1 +2 +3 +``` cat argshift1.sh ```bash #/bin/bash @@ -1014,7 +1316,11 @@ done $ chmod 777 argshift.sh ## OUTPUT $ ./argshift.sh 1 2 3 - +``` +1 + 2 + 3 + ``` cat argshift.sh ```bash #!/bin/bash @@ -1027,8 +1333,10 @@ set +x ``` ## OUTPUT ./argshift.sh 1 2 3 - - + ``` ++ (( 0 )) + + set +x + ``` cat > nc.awk ```bash BEGIN{} @@ -1058,7 +1366,11 @@ ubcdfghj ``` awk -f nc.awk data.dat ## OUTPUT - + ``` +total characters 75 + Number of Lines are 10 + No of Words count: 10 +``` cat > palindrome.sh ```bash #num=545 @@ -1085,7 +1397,13 @@ else fi ``` ## OUTPUT - - +``` +Enter the number + 121 + Number is palindrome + Enter the number + 69 + Number is NOT palindrome +``` # RESULT: The Commands are executed successfully.