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

UNIX Lab File - A50105221081

Unix lab file

Uploaded by

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

UNIX Lab File - A50105221081

Unix lab file

Uploaded by

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

UNIX LAB FILE

Submitted By: Submitted To:


Sayan Bhattacharyya Ms. Priyanka Makkar

A50105221081 Assistant Professor

B.Tech (CSE) 3rd - B ASET (CSE)


INDEX

Page
S.No. Topic Practical Signature
No.
Unix
1. Unix Commands 1-15
Commands

2. vi editor vi editor 16-17

3. Addition of two numbers 18

4. Subtraction of two numbers 18

5. Multiplication of two numbers 19

6. Division of two numbers 19

One number raised to the power of


7. 20
another number
Shell Scripts
Swap two numbers using third
8. 20
variable.
Swap two numbers without using
10. 21
third variable.

11. Table of a number. 21-22

12. Largest among three numbers. 22-23

13. Fibonacci Series. 23-24


PRACTICAL NO. 1
Unix commands

Unix -- trademarked as UNIX -- is a multiuser, multitasking operating system


(OS) designed for flexibility and adaptability. Originally developed in the 1970s,
Unix was one of the first OSes to be written in the C programming language.
Since its introduction, the Unix operating system and its offshoots have had a
profound effect on the computer and electronics industry, offering portability,
stability and interoperability across a range of heterogeneous environments and
device types.

pwd command

Theory: This command prints the full pathname of the current working
directory.

Syntax: pwd [options]

Output:

cd command

Theory: This command is used to change the directory.

Syntax: cd [directory | ~ | ./ | ../ | - ]

Output:
ls command

Theory: This command lists the files and directories under current working
directory.

Syntax: ls [options] [file]

Output:

rm command

Theory: This command is used to remove/delete the file from the directory.

Syntax: rm [options] [file | directory]

Output:
mv command

Theory: This command is short for move. It is used to move/rename file from
one directory to another. mv command is different from cp command as it
completely removes the file from the source and moves to the directory
specified, where cp command just copies the content from one file to another.

Syntax: mv [-f] [-i] oldname newname

Output:

cat command

Theory: This command is used to create a new file and to display the contents
of already existing file.

Syntax:

• For displaying contents of file: cat [filename]


• For creating new file: cat > filename

Output:
cmp command

Theory: cmp command compares two files and tells you which line numbers are
different.

Syntax: cmp [options] file1 file2

Output:

cp command

Theory: This command copies files from one location to another. If the
destination is an existing file, then the file is overwritten; if the destination is an
existing directory, the file is copied into the directory (the directory is not
overwritten).

Syntax: cp [options] source destination

Output:

bc command

Theory: This command is used for command line calculator. It is similar to


basic calculator. By using which we can do basic mathematical calculations.

Syntax: bc [options]

Output:
echo command

Theory: This command prints the given input string to standard output.

Syntax: echo [options] [string]

Output:

mkdir command

Theory: This command is used to create one or more directories.

Syntax: mkdir [options] directories

Output:

paste command

Theory: This command is used to paste the content from one file to another
file. It is also used to set column format for each line.

Syntax: paste [options]

Output:
rmdir command

Theory: This command is used to delete/remove a directory and its


subdirectories.

Syntax: rmdir [options] directory

Output:

wc command

Theory: This command counts the characters, words or lines in a file depending
upon the option.
Syntax: wc [options] filename

Output:

cal command

Theory: This command will print the calendar of current month by default.

Syntax: cal [options]

Output:
clear command

Theory: This command clears the screen and puts cursor at beginning of first
line.

Syntax: clear

Output:

tty command

Theory: This command prints the file name of the terminal connected to
standard input.

Syntax: tty [options]

Output:

banner command

Theory: This command prints characters in a sort of ascii art poster.

Syntax: banner word


Output:

who command

Theory: This command tells you who's logged on, and where they're coming
from. Useful if you're looking for someone who's actually physically in the same
building as you, or in some other particular location.

Syntax: who

Output:
date command

Theory: This command prints or sets the system date and time.

Syntax: date [options]

Output:

chmod command

Theory: This command will give all permissions to the owner (i.e read, write
and execute) while read and execute permissions only to others and group.

Syntax: chmod [options] filename

Output:

touch command

Theory: This command is used to create a new empty file.


Syntax: touch filename

Output:

uname command

Theory: This command prints information about the current system.

Syntax: uname [options]

Output:

ps command

Theory: This command displays active processes.

Syntax: ps [options]

Output:
exit command

Theory: Issuing this command will cause the shell to exit.

Syntax: ps [options]

Output: (The shell will terminate)


PRACTICAL NO. 2
vi editor

Theory:

Developed at the University of California, vi (visual editor) is an interactive,


screen-oriented text editor installed on almost every Unix system. vi does not
use graphics and is also relatively small. Hence it can be used to display a file in
situations when using X-Windows is not an option (e.g., when connected
through a modem).

Syntax:

vi filename

Command Mode:
Input Mode:

Line Mode:
PRACTICAL NO. 27
Write a shell script to perform addition of two numbers.

1 echo "Enter first number: "


2 read a
3 echo "Enter second number: "
4 read b
5 c=$(($a + $b))
6 echo "Result: ${c}"

PRACTICAL NO. 28
Write a shell script to perform subtraction of two numbers.

1 echo "Enter first number: "


2 read a
3 echo "Enter second number: "
4 read b
5 c=$(($a - $b))
6 echo "Result: ${c}"
PRACTICAL NO. 29
Write a shell script to perform multiplication of two numbers.

1 echo "Enter first number: "


2 read a
3 echo "Enter second number: "
4 read b
5 c=$(($a * $b))
6 echo "Result: ${c}"

PRACTICAL NO. 30
Write a shell script to perform division of two numbers.

1 echo "Enter first number: "


2 read a
3 echo "Enter second number: "
4 read b
5 c=$(($a / $b))
6 echo "Result: ${c}"
PRACTICAL NO. 31
Write a shell script to raise one number to the power of another.

1 echo "Enter first number: "


2 read a
3 echo "Enter second number: "
4 read b
5 c=$(($a ** $b))
6 echo "Result: ${c}"

PRACTICAL NO. 32
Write a shell script to swap two numbers using third variable.

1 echo "Enter first number: "


2 read a
3 echo "Enter second number: "
4 read b
5 t=$a
6 a=$b
7 b=$t
8 echo "Numbers after swapping are: ${a} and ${b}"
PRACTICAL NO. 33
Write a shell script to swap two numbers without using third variable.

1 echo "Enter first number: "


2 read a
3 echo "Enter second number: "
4 read b
5 a=$((a + b))
6 b=$((a - b))
7 a=$((a - b))
8 echo "Numbers after swapping are: ${a} and ${b}"

PRACTICAL NO. 34
Write a shell script to print the table of a number.

1 echo "Enter the number: "


2 read n
3 for i in 1 2 3 4 5 6 7 8 9 10
4 do
5 x=$((n * i))
6 echo "${n} * ${i} = ${x}"
7 done
PRACTICAL NO. 35
Write a shell script to print the largest of three numbers.

1 echo "Enter first number: "


2 read a
3 echo "Enter second number: "
4 read b
5 echo "Enter third number: "
6 read c
7
8 l=$a
9
10 if [ $b -gt $l ]
11 then
12 l=$b
13 fi
14
15 if [ $c -gt $l ]
16 then
17 l=$c
18 fi
19
20 echo "Largest of the three numbers is: ${l}"
PRACTICAL NO. 36
Write a shell script to print the Fibonacci series.

1 echo "How many terms should be generated?"


2 read n
3
4 x=0
5 y=1
6 i=2
7
8 echo "Fibonacci Series up to ${n} terms: "
9 echo "$x"
10 echo "$y"
11
12 while [ $i -lt $n ]
13 do
14 i=`expr $i + 1 `
15 z=`expr $x + $y `
16 echo "$z"
17 x=$y
18 y=$z
19 done

You might also like