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

UNIX

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

UNIX

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

BTIT408N December 30, 1899

Experiment 1
Aim:- To learn linux commands
1. Cal:- Linux command to display
calendar. Output:-

2. Date:- Linux command to display date


Output:-

3. W:-Linux command to display the list of users who are currently using
Linux server.
Output:-

4. Lscpu:- Linux command to display your system details.


Outut:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

8. Echo:- Linux command to print the content on standard output


device.
Output:-

9. Expr:- Linux command to perform calculations.


Output:-

10. Pwd :-Linux command to show the current working


directory. Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 2
Aim:- to learn linux commands.
1. Help:-Linux command to get help with various options.
Output:-

2. W:- Linux command to display what all users are currently


doing. Output:-

3. Mkdir:- Linux command to create a


directory. Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

4. Cd and cd .. :- Linux command to change the


directory. Output:-

5. Rmdir:- Linux command to remove a


directory. Output:-

6. Rm:- Linux command to delete file.


Output:-

7. Cp:- linux command to copy file.


Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

8. Mv:- Linux command to move a file to some different


location. Output:-

9. Diff:- Linux command to compare the contents of two


files. Output:-

10. Vimdiff:- Linux command to show the difference between


the contents of two files.
Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 3
Aim:- to learn linux commands.
1. Comm:- Linux command to show the common data of two files.
Output:-

2. Wc:- Linux command to count the number of words, lines, and


sentences in the file.
Output:-

3. Od:- Linux command to see the data in octal format.


Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

4. Alias:- Linux command to give the alias name.


Output:-

5. Hostname:- Linux command to display the hostname of the system.


Output:-

6. Uname:- Linux command to get informaion about the operating


System.
Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

7. Type:- Linux command to check whether a command is Internal


or External.
Output:-

8. Uniq:- Linux command to display unique contents of a file.


Output:-

9. Head:- Linux command to view the first 5 lines of a file.


Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 4
Aim:- to learn linux commands.
1. Tail:- Linux command to view the last 20 lines of a
file. Output:-

2. Awk:- Linux command to extract specific column and field from a


file. Output:-

3. Paste:- Linux command to merge two files


vertically. Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

4. Sort:- Linux command to sort a file.


Output:-

5. Sed:- Linux command to find any character and replace it with some
other character.
output:-

6. Ls -l :- Linux command to check the default permission of a file.


Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

7. Umask / man :- Linux command to change the default permission of a


file.
Output:-

8. Chmod:- Linux command to change the permission of an existing file


in relative manner.
Output:-

9. Chmod 1 2 4:- Linux command to change the permission of an


existing file in absolute manner.
Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 5
Aim:- Program to print hello world.
Code:-

Echo “Hello World”

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 6
Aim:- Program to Display calendar.
Code:-

Echo “The Month is”

Cal # cal command displays current month by


default

Echo “An alternate view of calender”

Ncal # An alternale layout for calender

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 7
Aim:- Program to a simple script to read user input and perform
operations with them.
Code:-

Echo -n “Enter number 1 : “ # -n option supresses newline

Read NUM1 # Read the user input from Standard Input and store in Variable
NUM1

Echo -n “Enter number 2 : “


Read NUM2
SUM=$(($NUM1 + $NUM2)) # Arithmetic expansion using double parentheses
Echo “The sum is $SUM”
SUM=`expr $NUM1 + $NUM2` # Arithmetic expansion using backticks.
#Usage of expr command to evaluate the expression

Echo “The sum is $SUM”

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 8
Aim:- A script to show usage of if condition.
Code:-

NUM1=5 # variabe assignment


NUM2=2
If [ $NUM1 -gt $NUM2 ] # -gt is to test intiger
numbers
Then
echo “NUM1 > NUM2”

Fi

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 9
Aim:- A script to show usage of if else
condition. Code:-

Echo -n “Enter a number: “


Read NUM
If [ $NUM -gt 0 ]
Then
Echo “$NUM is +ve”
Elif [ $NUM -lt 0 ]
Then

Echo “$NUM is -ve”


Else
Echo “$NUM is 0”
Fi
Echo “done”

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 10
Aim:- A script to demonstrate case
statement. Code:-

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 11
Aim:- A script to demonstrate case statement.
Code:-
Echo -n “Enter a character: “
Read CHAR
Case $CHAR in

A | A) # Test for both lowercase or uppercase letter


Echo “You entered $CHAR which is a vowel”
;; # Terminates each option
E | E)
Echo “You entered $CHAR which is a vowel”

;;

I | I)
Echo “You entered $CHAR which is a vowel”

;;
O | O)
Echo “You entered $CHAR which is a vowel”

;;
U | U)
Echo “You entered $CHAR which is a vowel”

;;
*) # Defaults to everything else

Echo “You entered $CHAR which is not a vowel”

;;

Esac

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 12
Aim:- A script to demonstrate case
statement. Code:-

Echo -n “Oceans are larger than lakes (True or False) : “


Read USER_INPUT

Case “$USER_INPUT” in

[Tt][Rr][Uu][Ee] ) # Matches True or true (case-insensitive)


Echo “Yes, you are right!”
;;

[Ff][Aa][Ll][Ss][Ee] ) # Matches False or false (case-insensitive)


Echo “No, you are wrong.”
;;

 ) # Default case for any other input


Echo “Invalid input. Please enter either ‘True’ or ‘False’.”
;;

Esac

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 13
Aim:- A simple script to show usage of string compare operator =
and !=.
Code:-

STR1=”Hello”

STR2=”Hello”

If [ ${STR1} = ${STR2} ]

Then

Echo “Strings match”

Else

Echo “Strings don’t match”

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 14
Aim:- A simple script to show usage of string compare operator -z
and -n.
Code:-

STR1=”Hello”
STR2=”Hello”

# Check if STR1 is empty


If [[ -z “${STR1}” ]]; then
Echo “String1 is empty”
Else
Echo “String1 is NOT empty”

Fi

# Print STR1 with colon on both sides


Echo “:$STR1:”

# Check if STR2 is empty


If [[ -z “${STR2}” ]]; then
Echo “String2 is empty”
Else
Echo “String2 is NOT empty”
Fi

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 15
Aim:- A simple script to show usage of logical
operators. Code:-

Echo -n “Enter a NUM: “


Read NUM

If [[ $NUM -ge 10 && $NUM -le 20 ]]; then


Echo “$NUM is between 10 and 20”
Else

Echo “$NUM is NOT between 10 and 20”


Fi

Echo -n “Enter another NUM: “


Read NUM

If [[ $NUM -lt 10 || $NUM -gt 20 ]]; then


Echo “$NUM is NOT between 10 and 20”
Else

Echo “$NUM is between 10 and 20”


Fi

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 16
Aim:- A simple script to show usage while loop
Code:-

COUNT=0

While [ $COUNT -lt 5 ]


Do
Echo “Loop count is
${COUNT}” COUNT=$
((COUNT + 1))
Done

Echo “Done”

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 17
Aim:- Sum of N natural numbers using while
loop. Code:-

Echo -n “Enter a number: “

Read NUM

Let SUM=0;

Let I=1

While [ $I -le $NUM ]

Do

SUM=`expr $SUM + $I`

I=$((${I} + 1))

Done

Echo “The sum of the first $NUM numbers is: $SUM”

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 18
Aim:- A simple script to demonstrate for
loop. Code:-

COUNT=0

For I in 0 1 2 3 4

Do

Echo “Loop count is ${COUNT}”

COUNT=$((COUNT + 1))

Done

Output:-

22100BTCSE11369 Aagam Jain


BTIT408N December 30, 1899

Experiment 19
Aim:- A script to show usage of if else
condition. Code:-

NUM1=2 # Variabe assignment

NUM2=5

If [ $NUM1 -lt $NUM2 ] # -lt is to test intiger numbers

Then

Echo “NUM1 < NUM2”

Else

Echo “NUM1 > NUM2”

Fi

Output:-

22100BTCSE11369 Aagam Jain

You might also like