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

Prac 4 Linux

Uploaded by

Khan Nùzhát
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)
13 views

Prac 4 Linux

Uploaded by

Khan Nùzhát
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/ 7

Linux Practical-4

General Purpose Utility and More Bash Shell Commands

1. Display the calendar of the current month of the current year.


guest-MmIkKm@ubuntu:~$ cal
January 2017
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

2. Display the calendar of the year 2009.


guest-MmIkKm@ubuntu:~$ cal 2009
2009
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 1 2 3 4 5 6 7 1 2 3 4 5 6 7
4 5 6 7 8 9 10 8 9 10 11 12 13 14 8 9 10 11 12 13 14
11 12 13 14 15 16 17 15 16 17 18 19 20 21 15 16 17 18 19 20 21
18 19 20 21 22 23 24 22 23 24 25 26 27 28 22 23 24 25 26 27 28
25 26 27 28 29 30 31 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 1 2 1 2 3 4 5 6
5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
31

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 1 1 2 3 4 5
5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30
30 31

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 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

3. Display the calendar of the month July of the year 1998.


guest-MmIkKm@ubuntu:~$ cal 07 1998
July 1998
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

4. Display today’s date.


guest-MmIkKm@ubuntu:~$ date
Mon Jan 2 01:22:23 PST 2017

5. Display date as mm/dd/yy.


guest-MmIkKm@ubuntu:~$ date +%D
01/02/17

6. Display current hour, minutes and seconds separately.


guest-MmIkKm@ubuntu:~$ date +%H
01
guest-MmIkKm@ubuntu:~$ date +%M
37
guest-MmIkKm@ubuntu:~$ date +%S
55

7. Display time in hours, minutes and seconds as HH:MM:SS.


guest-MmIkKm@ubuntu:~$ date +%T
01:31:15

8. Display abbreviated month name.


guest-MmIkKm@ubuntu:~$ date +%h
Jan

9. Display day of the week.


guest-MmIkKm@ubuntu:~$ date +%d
02

10. Display full weekday.


guest-MmIkKm@ubuntu:~$ date +%A
Monday

11. Display abbreviated weekday.


guest-MmIkKm@ubuntu:~$ date +%a
Mon

12. Display time in AM/PM notation.


guest-MmIkKm@ubuntu:~$ date +%r
01:31:08 AM

13. Display last two digits of the year.


guest-MmIkKm@ubuntu:~$ date +%y
17

14. Display full year.


guest-MmIkKm@ubuntu:~$ date +%Y
2017

15. Display the date and time on two different lines.


guest-MmIkKm@ubuntu:~$ date +%D%n%T
01/02/17
01:41:09

16. Calculate the following using bc command:-


i) 6+7
guest-MmIkKm@ubuntu:~$ bc
6+7
13

ii) 12 * 12
12*12
144

iii) 144 / 3
144/3
48

iv) scale = 2 25 / 7

v) (8 + 2) * 5
(8+2)*5
50

vi) (2 + 3) + 8 - 4 * (6 – 3)
(2+3)+8-4*(6-3)
1

vii) 2^6
2^6
64

viii) 12*12; 12 / 6
12*12;12/6
144
2

ix) ibase=2
11001010
ibase=2
11001010
202

x) obase=2
14
obase=2
14
11

17. Display all the users currently logged in the system.


guest-MmIkKm@ubuntu:~$ who
guest-MmIkKm pts/1 2017-01-02 01:03 (:0)

18. Display the login name of the current terminal.


guest-MmIkKm@ubuntu:~$ who am i
guest-MmIkKm pts/1 2017-01-02 01:03 (:0)

19. Display all the users currently logged in the system with heading.
guest-MmIkKm@ubuntu:~$ who -Hu
NAME LINE TIME IDLE PID COMMENT
guest-MmIkKm pts/1 2017-01-02 01:03 . 2541 (:0)

20. Display the terminal file of the current terminal.


guest-MmIkKm@ubuntu:~$ tty
/dev/pts/1

21. Display the message on to the terminal as “Hello World”.


guest-MmIkKm@ubuntu:~$ echo Hello World
Hello World

22. Display the message on to the terminal as “Hello World”.


guest-MmIkKm@ubuntu:~$ echo "Hello World"
Hello World

23. What will be the output of the following:-


i) x = 10
echo The value of x is $x
guest-MmIkKm@ubuntu:~$ echo The value of x is $x
The value of x is 10
ii) str=”Linux Practical 1”
echo The string is $str
guest-MmIkKm@ubuntu:~$ echo The string is $str
The string is Linux Practical 1

iii) d=`date`
echo “Today’s date is $d”
guest-MmIkKm@ubuntu:~$ echo "Today's date is $d"
Today's date is Mon Jan 2 02:08:19 PST 2017

iv) echo “The number of users currently logged in are `who` ”


guest-MmIkKm@ubuntu:~$ echo "The numbers of users currently logged in are
`who`"The numbers of users currently logged in are guest-MmIkKm pts/1
2017-01-02 01:03 (:0)

24. Find the type of all files.


guest-URijZ7@ubuntu:~$ file *
Desktop: directory
Documents: directory
Downloads: directory
examples.desktop: UTF-8 Unicode text
Music: directory
Pictures: directory
Public: directory
Templates: directory
Videos: directory

25. Display and count the number of lines, words and characters of file “demo”.
guest-URijZ7@ubuntu:~$ cat demo
a
d
c
d

guest-URijZ7@ubuntu:~$ wc demo
5 4 9 demo

26. Display and count the number of lines of file “demo”.


guest-URijZ7@ubuntu:~$ file *
demo: ASCII text
demo.txt: empty
Desktop: directory
Documents: directory
Downloads: directory
examples.desktop: UTF-8 Unicode text
Music: directory
Pictures: directory
Public: directory
Templates: directory
Videos: directory

27. Display and count the number of words of file “demo”.


guest-URijZ7@ubuntu:~$ wc -w demo
4 demo

28. Display and count the number of characters of file “demo”.


guest-URijZ7@ubuntu:~$ wc -c demo
9 demo

29. Display and count the number of lines, words and characters of file “demo” and “example”
and “test”.
guest-URijZ7@ubuntu:~$ wc demo example test
5 4 9 demo
4 4 8 example
3 3 6 test
12 11 23 total

30. Count the number of all files and directories.


guest-URijZ7@ubuntu:~$ ls|wc -l
13

31. Count the number of all users currently logged in to the system.
guest-URijZ7@ubuntu:~$ who|wc -l
1

32. Store the number of users currently logged in to the system in file “testdemo”.
guest-URijZ7@ubuntu:~$ who|wc -l > testdemo
guest-URijZ7@ubuntu:~$ cat testdemo
1

33. Display and store the listing of all filenames in file “list”.
guest-URijZ7@ubuntu:~$ ls| tee list
demo
demo.txt
Desktop
Documents
Downloads
example
examples.desktop
Music
Pictures
Public
Templates
test
testdemo
Videos

34. Display and store the list of all users currently logged in into the system in file users.
guest-URijZ7@ubuntu:~$ ls| tee users
demo
demo.txt
Desktop
Documents
Downloads
example
examples.desktop
list
Music
Pictures
Public
Templates
test
testdemo
users
Videos

35. Save your work and logout from current terminal.

You might also like