Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Lab Exercises for UNIX

Lab 1

1. Obtain the following results

(i) To print the name of operating system

ankit@ankit-VirtualBox:~$ uname

Linux

(ii) To print the login name

ankit@ankit-VirtualBox:~$ who

ankit tty7 2023-08-16 13:04 (:0)

(iii) To print the host name

ankit@ankit-VirtualBox:~$ whoami

ankit

2. Find out the users who are currently logged in and find the particular user too.

3. Display the calendar for

(i) Jan 2000

ankit@ankit-VirtualBox:~$ cal jan 2000

January 2000

Su Mo Tu We Th Fr Sa

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
(ii) Feb 1999

ankit@ankit-VirtualBox:~$ cal feb 1999

February 1999

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

(iii) 9 th month of the year 7 A.D

ankit@ankit-VirtualBox:~$ cal 9 700

September 700

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

(iv) For the current month

ankit@ankit-VirtualBox:~$ cal

August 2023

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

(v) Current Date Day Abbreviation , Month Abbreviation along with year

ankit@ankit-VirtualBox:~$ date +"%d%a%b%y"

17ThuAug23
4. Display the time in 12-Hour and 24 Hour Notations.

ankit@ankit-VirtualBox:~$ date '+%I:%M%p';date '+24-hour format :%H:%M'

09:59PM

24-hour format :21:59

5. Display the Current Date and Current Time.

ankit@ankit-VirtualBox:~$ date

Thursday 17 August 2023 10:10:55 PM IST

6. Display the message “GOOD MORNING” in enlarged characters.

ankit@ankit-VirtualBox:~$ echo "GOOD MORNING"

GOOD MORNING

7. Display the name of your home directory.

ankit@ankit-VirtualBox:~$ echo ~

/home/ankit

8. Create a directory SAMPLE under your home directory.

ankit@ankit-VirtualBox:~$ mkdir SAMPLE

ankit@ankit-VirtualBox:~$ cd SAMPLE

ankit@ankit-VirtualBox:~/SAMPLE$

9. Create a sub-directory by name TRIAL under SAMPLE.

ankit@ankit-VirtualBox:~/SAMPLE$ mkdir TRIAL

ankit@ankit-VirtualBox:~/SAMPLE$ cd TRIAL

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$

10. Change to SAMPLE.

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ cd ..

ankit@ankit-VirtualBox:~/SAMPLE$

11. Change to your home directory.

ankit@ankit-VirtualBox:~/SAMPLE$ cd ..

ankit@ankit-VirtualBox:~$

12. Change from home directory to TRIAL by using absolute and relative pathname.

ankit@ankit-VirtualBox:~/SAMPLE/NEW$ cd

ankit@ankit-VirtualBox:~$ cd /home/ankit/SAMPLE/NEW/TRUIAL
ankit@ankit-VirtualBox:~/SAMPLE/NEW/TRUIAL$

13. Remove directory TRIAL.

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ cd ..

ankit@ankit-VirtualBox:~/SAMPLE$ ls

TRIAL

ankit@ankit-VirtualBox:~/SAMPLE$ rmdir TRIAL

ankit@ankit-VirtualBox:~/SAMPLE$ ls

ankit@ankit-VirtualBox:~/SAMPLE$

14. Create a directory TEST using absolute pathname.

ankit@ankit-VirtualBox:~/Desktop$ mkdir /home/ankit/Desktop/TESTankit ankit@ankit-


VirtualBox:~/Desktop$ cd TEST

ankit@ankit-VirtualBox:~/Desktop/TEST$ cd

ankit@ankit-VirtualBox:~$ cd Desktop

ankit@ankit-VirtualBox:~/Desktop$ cd /home/ankit/Desktop/TEST

15. Using a single command change from current directory to home directory.

ankit@ankit-VirtualBox:~/Desktop/TEST$ cd

16. Remove a directory using absolute pathname.

ankit@ankit-VirtualBox:~/Desktop$ ls

file ankit.u.sh links subject subjectrelative welcome.txt

filename ankit.sh printexample.sh subjectlink TEST

ankit@ankit-VirtualBox:~/Desktop$ rm -r /home/ankit/Desktop/TEST

ankit@ankit-VirtualBox:~/Desktop$ ls

file ankit.u.sh links subject subjectrelative

filename ankit.sh printexample.sh subjectlink welcome.txt


17. Create files myfile and yourfile under Present Working Directory.

ankit@ankit-VirtualBox:~$ cd SAMPLE

ankit@ankit-VirtualBox:~/SAMPLE$ cat > myself

This is My File in SAMPLE directory

^C

ankit@ankit-VirtualBox:~/SAMPLE$ chmod +x myself

ankit@ankit-VirtualBox:~/SAMPLE$ cat > youfile

This is the 2nd file in SAMPLE directory

^C

ankit@ankit-VirtualBox:~/SAMPLE$ chmod +x yourfile

18. Display the files myfile and yourfile.

ankit@ankit-VirtualBox:~/SAMPLE$ ls

myself youfile

19. Append more lines in the myfile and yourfile files.

ankit@ankit-VirtualBox:~/SAMPLE$ cat >> myfile

Hello Everyone

I am Ankit

^C

ankit@ankit-VirtualBox:~/SAMPLE$ cat >> yourfile

I am from Patna

I am parsuing BCA from AMITY UNIVERSITY PATNA.

^C

ankit@ankit-VirtualBox:~/SAMPLE$ cat myfile yourfile

Hello Everyone

I am Ankit

I am from Patna

I am parsuing BCA from AMITY UNIVERSITY PATNA.


20. How will you create a hidden file?.

ankit@ankit-VirtualBox:~/SAMPLE$ cat.ankit.txt

cat.ankit.txt: command not found

ankit@ankit-VirtualBox:~/SAMPLE$ cat > .ankit.txt

This is the hidden file

^C

ankit@ankit-VirtualBox:~/SAMPLE$ chmod +x .ankit.txt

ankit@ankit-VirtualBox:~/SAMPLE$ ls

myfile myself youfile yourfile

ankit@ankit-VirtualBox:~/SAMPLE$ cat .ankit.txt

This is the hidden file

21. Copy myfile file to emp.

ankit@ankit-VirtualBox:~/SAMPLE$ cat myfile >> emp

ankit@ankit-VirtualBox:~/SAMPLE$ cat emp

Hello Everyone

I am Amkit

22. Write the command to create alias name for a file.

ankit@ankit-VirtualBox:~/SAMPLE$ ln -s ship_bin

ankit@ankit-VirtualBox:~/SAMPLE$ ls

emp myfile myself ship_bin youfile yourfile

23. Move yourfile file to dept.

ankit@ankit-VirtualBox:~/SAMPLE$ cat yourfile >> dept

ankit@ankit-VirtualBox:~/SAMPLE$ cat dept

I am from Patna

I am parsuing BCA from AMITY UNIVERSITY PATNA.

I am from Patna

I am parsuing BCA from AMITY UNIVERSITY PATNA.


24. Copy emp file and dept file to TRIAL directory

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ cd ..

ankit@ankit-VirtualBox:~/SAMPLE$ cp emp dept TRIAL

ankit@ankit-VirtualBox:~/SAMPLE$ cd TRIAL

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ ls

dept emp

25. if you compare a file with itself.

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ cmp emp emp

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$

26. Compare myfile file and emp file.

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ cmp emp emp

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$

27. Append two more lines in emp file existing in TRIAL directory.

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ cmp emp emp

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ cat >> emp

Iam in 2nd year.

and the semester is 3rd.

^C

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ cat emp

Hello Everyone

I am Ankit

Iam in 2nd year.

and the semester is 3rd.

28. Compare employee file with emp file in TRIAL directory.

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ cmp employee emp employee emp differ: byte 9,line 1


29. Find the difference between the above file.

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ diff employee emp

1c1,4

< This is the employee file.

---

> Hello Everyone

> I am Ankit

> Iam in 2nd year.

> and the semester is 3rd.

30. Remove the files in the TRIAL directory.

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ ls

dept emp employee

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ rm dept emp employee

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ ls

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$

31. Can you remove a directory with files by using a single command.

Yes

ankit@ankit-VirtualBox:~/SAMPLE$ ls

DATA dept emp myfile myself NEW ship_bin youfile yourfile

ankit@ankit-VirtualBox:~/SAMPLE$ cd NEW

ankit@ankit-VirtualBox:~/SAMPLE/NEW$ ls

TRUIAL

ankit@ankit-VirtualBox:~/SAMPLE/NEW$ cd TRUIAL

ankit@ankit-VirtualBox:~/SAMPLE/NEW/TRUIAL$ ls

dummy star

ankit@ankit-VirtualBox:~/SAMPLE/NEW$ rm -r TRUIAL

ankit@ankit-VirtualBox:~/SAMPLE/NEW$ ls

ankit@ankit-VirtualBox:~/SAMPLE/NEW$

32. Is there any command available to get back a deleted file?


No,when we delete a file by rm command then file will not get back until we use any backup for it.

33. Rename TRIAL as DATA.

ankit@ankit-VirtualBox:~/SAMPLE/TRIAL$ cd ..

ankit@ankit-VirtualBox:~/SAMPLE$ ls

dept emp myfile myself ship_bin TRIAL youfile yourfile

ankit@ankit-VirtualBox:~/SAMPLE$ mv TRIAL DATA

ankit@ankit-VirtualBox:~/SAMPLE$ ls

DATA dept emp myfile myself ship_bin youfile yourfile

34. Copy DATA to another directory by name TRIAL.

ankit@ankit-VirtualBox:~/SAMPLE$ cp -r DATA NEW

ankit@ankit-VirtualBox:~/SAMPLE$ cd NEW

ankit@ankit-VirtualBox:~/SAMPLE/NEW$ ls

DATA

ankit@ankit-VirtualBox:~/SAMPLE/NEW$ mv DATA TRUIAL

ankit@ankit-VirtualBox:~/SAMPLE/NEW$ ls

TRUIAL

35. Create a file called dummy in TRIAL and link it to another file by name star.

ankit@ankit-VirtualBox:~/SAMPLE/NEW/TRUIAL$ cat > dummy

This is the dummy file.

^C

ankit@ankit-VirtualBox:~/SAMPLE/NEW/TRUIAL$ ln -s dummy star

ankit@ankit-VirtualBox:~/SAMPLE/NEW/TRUIAL$ ls

dummy star

36. Link the dummy file in TRIAL to another file by name power in DATA.

ankit@ankit-VirtualBox:~/SAMPLE$ ln -s dummy power/* DATA

ankit@ankit-VirtualBox:~/SAMPLE$ cd DATA

ankit@ankit-VirtualBox:~/SAMPLE/DATA$ ls

'*' dummy

You might also like