Share Shelloutput
Share Shelloutput
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
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 -
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
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:
Commands
i)
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ cat aa.txt|grep sakthi bb.txt
ii)
shell lab
iii)
3 aa.txt
shell lab
3 aa.txt
RESULT:
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:
Commands
guest-cdhexl@user-OptiPlex-3046:~/Desktop$ cal -3
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
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 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
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
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
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:
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
RESULT:
OUTPUT:
4.4$ sh s3.sh 23 54 65
65 is biggest number
RESULT:
OUTPUT:
4.4$ sh s4.sh
545
Number is palindrome
RESULT:
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:
OUTPUT:
4.4$ sh s9.sh
different
RESULT: