0% found this document useful (0 votes)
12 views16 pages

Share Shelloutput

The script displays a menu with options to display the date and time, username, file listing, and directories. It prompts the user to select an option and executes the corresponding command. The script then asks if the user wants to continue or exit.

Uploaded by

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

Share Shelloutput

The script displays a menu with options to display the date and time, username, file listing, and directories. It prompts the user to select an option and executes the corresponding command. The script then asks if the user wants to continue or exit.

Uploaded by

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

COMMANDS:

a) rm (Remove) - Delete a file or directory tree

sh-4.4$ rm ss.txt
b) cp – Copy a file or directory to another location
sh-4.4$ cp aa.txt bb.txt
c) cat – Concatenate files to standardoutput
sh-4.4$ cat aa.txt bb.txt
sh-4.4$ cat aa.txt cc.txt > xyz.txt
d) mv – Move or rename a file or directory
sh-4.4$ mv aa.txt bb.txt
e) Compare two files byte for byte
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ cmp aa.txt bb.txt
aa.txt bb.txt differ: byte 3, line 1
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ cmp aa.txt bb.txt
aa.txt bb.txt differ: byte 3, line 1
f)wc – Word/line/byte count
$ wc – l File_Name - is used to calculate the no of lines in specific file
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ wc -l aa.txt
3 aa.txt

$ wc – w File_Name - is used to calculate the no of words in specific file.


guest-cdhexl@user-OptiPlex-3046:~/Desktop$ wc -w aa.txt
5 aa.txt

$ wc – c File_Name - is used to calculate the no of characters in file.


guest-cdhexl@user-OptiPlex-3046:~/Desktop$ wc -c aa.txt
43 aa.txt
$ wc –lw File_Name - is used to calculate line and word for specific file.
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ wc -lw aa.txt
3 5 aa.txt
$ wc –lc File_Name - is used to calculate line and character for specific
file.
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ wc -lc aa.txt
3 43 aa.txt
g)split – Split a file into pieces
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ split -d aa.txt
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ ls
aa.txt bb.txt x00
h)diff – Compare two text files line by line

guest-cdhexl@user-OptiPlex-3046:~/Desktop$ diff aa.txt bb.txt


1,3c1
< shri sakthikailassh women's college
< salem

RESULT:
Thus the above command has been executed successfully.
COMMANDS:
a) currently logged user and his log name
sh-4.4$ whoami
guest-cdhexl
b) current shell , home directory , Operating System type , current path
setting , current working directory
i) Current Shell
sh4.4$ echo $0
bash
ii)Home Directory
sh4.4$ echo $HOME
/tmp/guest-cdhexl
iii)Operating System Type
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
UBUNTU_CODENAME=xenial

iv)Current Path
sh4.4$ echo $PATH
guest-ud0dcb@user-OptiPlex-3046:~/Desktop/harini$ (echo $PATH)
/tmp/guest-ud0dcb/bin:/tmp/guest-ud0dcb/.local/bin:/usr/local/sbin:/usr/local/
bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
c) Show currently logged number of user show all available shell

$pwd
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ pwd
/tmp/guest-cdhexl/Desktop
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ w
19:40:37 up 4:08, 1 user, load average: 0.00, 0.03, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
guest-cd tty7 :0 15:32 4:08m 28.02s 0.11s /sbin/upstart -

d)Show CPU information like processor speed

guest-cdhexl@user-OptiPlex-3046:~/Desktop$ lscpu
Architecture: i686
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 94
Model name: Intel(R) Pentium(R) CPU G4400 @ 3.30GHz
Stepping: 3
CPU MHz: 899.894
CPU max MHz: 3300.0000
CPU min MHz: 800.0000
BogoMIPS: 6624.15
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx pdpe1gb rdtscp lm
constant_tsc art arch_perfmon pebs bts xtopology nonstop_tsc aperfmperf eagerfpu
pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg cx16 xtpr pdcm pcid
sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave rdrand lahf_lm
abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase
tsc_adjust erms invpcid rdseed smap clflushopt xsaveopt xsavec xgetbv1 dtherm
arat pln pts hwp hwp_notify hwp_act_window hwp_epp

e)show memory information

guest-cdhexl@user-OptiPlex-3046:~/Desktop$ vmstat -s
4013772 K total memory
452888 K used memory
567460 K active memory
432652 K inactive memory
2945716 K free memory
44036 K buffer memory
571132 K swap cache
0 K total swap
0 K used swap
0 K free swap
8361 non-nice user cpu ticks
0 nice user cpu ticks
3337 system cpu ticks
2967323 idle cpu ticks
7368 IO-wait cpu ticks
0 IRQ cpu ticks
58 softirq cpu ticks
0 stolen cpu ticks
375870 pages paged in
10716 pages paged out
0 pages swapped in
0 pages swapped out
946894 interrupts
1294652 CPU context switches
1569060104 boot time
2274 forks

RESULT:

Thus the above command has been executed successfully.

Commands

i)
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ cat aa.txt|grep sakthi bb.txt

shri sakthikailassh women's college

ii)

guest-cdhexl@user-OptiPlex-3046:~/Desktop$ cat bb.txt

shri sakthikailassh women's college

shell lab

iii)

guest-cdhexl@user-OptiPlex-3046:~/Desktop$ wc -l aa.txt|tee -a bb.txt

3 aa.txt

guest-cdhexl@user-OptiPlex-3046:~/Desktop$ cat bb.txt

shri sakthikailassh women's college

shell lab

3 aa.txt

RESULT:

Thus the above command has been executed successfully

SCRIPT CODE:

choice=0
while [ $choice -ne 5 ]
do
tput clear
echo "1.Display Date & Time"
echo "2.UserName
echo "3.File listing"
echo "4.Display Directories"
echo "5.Exit"
echo "Enter choice"
read choice
if [ $choice - eq1 ]
then
now=$(done)
echo "Current Date:$how"
elif [ $choiice - eq2 ]
then
echo "UserName"
id -un
elif [ $choice - eq3 ]
then
echo "File Listing"
ls -a
elif [ $choice - eq4 ]
then
echo "Display Directories"
ls -d
fi
elif [ $choice - eq5 ]
exit
fi
echo "Are you continue (Y for 1/0 for N)"
read temp
if [ $temp - eq0 ]
then
choice=5
fi
done

Output:
RESULT:

Thus the above script Program has been executed successfully.

Commands
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ cal -3

August 2019 September 2019 October 2019

Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

1 2 3 1 2 3 4 5 6 7 1 2 3 4 5

4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12

11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19

18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26

25 26 27 28 29 30 31 29 30 27 28 29 30 31

guest-cdhexl@user-OptiPlex-3046:~/Desktop$ cal 2019

2019

January February March

Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

1 2 3 4 5 1 2 1 2

6 7 8 9 10 11 12 3 4 5 6 7 8 9 3 4 5 6 7 8 9

13 14 15 16 17 18 19 10 11 12 13 14 15 16 10 11 12 13 14 15 16

20 21 22 23 24 25 26 17 18 19 20 21 22 23 17 18 19 20 21 22 23

27 28 29 30 31 24 25 26 27 28 24 25 26 27 28 29 30

31

April May June

Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 1 2 3 4 1

7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8

14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15

21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22

28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29

30
July August September

Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 1 2 3 1 2 3 4 5 6 7

7 8 9 10 11 12 13 4 5 6 7 8 9 10 8 9 10 11 12 13 14

14 15 16 17 18 19 20 11 12 13 14 15 16 17 15 16 17 18 19 20 21

21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28

28 29 30 31 25 26 27 28 29 30 31 29 30

October November December

Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

1 2 3 4 5 1 2 1 2 3 4 5 6 7

6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14

13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21

20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28

27 28 29 30 31 24 25 26 27 28 29 30 29 30 31

guest-cdhexl@user-OptiPlex-3046:~/Desktop$ cal 3 2019

March 2019

Su Mo Tu We Th Fr Sa

1 2

3 4 5 6 7 8 9

10 11 12 13 14 15 16

17 18 19 20 21 22 23

24 25 26 27 28 29 30

31

RESULT:

Thus the above command has been executed successfully.


SCRIPT CODE:

Num=123
g=$Num
#store the sum of
#digits
s=0
k=0
#use while loop to
#calculate the sum
#of all digits
while [ $Num - gt0 ]
do
#get remainder
k= $(( $Num%10))
#get next digit
Num= $(($Num/10))
#calculate sum of
#digits
s= $(($s+$k))
done
echo "Sum of digits of $g is:$s"

OUTPUT:

4.4$ sh s2.sh

1234

sum of digits of 1234 is : 10

RESULT:

Thus the above script has been executed successfully.


SCRIPT CODE:

echo "Enter 3 Number"


read a
read b
read c
if [ $a - gt $b ]&& [ $a - eq $c ]
then
echo "Three numbers are equal"
elif [ $a - gt $b ]&& [ $a - eq $c ]
then
echo "$a is Greatest Number"
elif [ $b - gt $c ]
then
echo "$b is Greatest Number"
else
echo "$c is Greatest Number"
fi

OUTPUT:

4.4$ sh s3.sh 23 54 65

65 is biggest number

RESULT:

Thus the above script has been executed successfully.


SCRIPT CODE:

echo "Enter number"


read n
number=$n
reverse=0
while [ $n -gt0 ]
do
a=$(($n%10))
n=$(($n/10))
reverse=$(($reverse*10+$a))
done
if [ $number -eq $reverse ]
then
echo "Number is palindrome"
else
echo "Number is not palindrome"
fi

OUTPUT:

4.4$ sh s4.sh

545

Number is palindrome

RESULT:

Thus the above script has been executed successfully.


SCRIPT CODE:

echo "Multiplication table"


read n
i =1
for i in 1 2 3 4 5 6
do
echo "$n*Si = $(($n*$i)'
done

OUTPUT:

sh-4.4$ sh s5.sh
Type any number to generate mathematical table

4 * 1 =4

4 * 2 =8

4 * 3 =12

4 * 4 =16

4 * 5 =20

4 * 6 =24

RESULT:

Thus the above script has been executed successfully.


SCRIPT CODE:

echo "Enter file:"


read file1
Echo "Enter file2:"
read file2
cmp $file1 $file2>newfile
x='wcnewfile |cut -d" " -f2'
if [ '$x -eq 0]
then
rm -i $file2
fi

OUTPUT:

4.4$ sh s9.sh

Enter File 1:aa.txt

Enter file 2:bb.txt

different

RESULT:

Thus the above script has been executed successfully.

You might also like