0% found this document useful (0 votes)
2 views15 pages

Unix and Shell Programming

This document outlines an assignment for Unix and Shell Programming focusing on file systems, detailing exercises to create directories, files, and links. It includes step-by-step instructions for navigating the terminal, creating and managing files, and utilizing commands like 'find' and 'ln'. The assignment aims to enhance understanding of file system operations and best practices in Unix environments.
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)
2 views15 pages

Unix and Shell Programming

This document outlines an assignment for Unix and Shell Programming focusing on file systems, detailing exercises to create directories, files, and links. It includes step-by-step instructions for navigating the terminal, creating and managing files, and utilizing commands like 'find' and 'ln'. The assignment aims to enhance understanding of file system operations and best practices in Unix environments.
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/ 15

Unix and Shell Programming

Assignment 2 –File Systems

Batch 2023-2028 Academic Year 2023-2024


ODD
Faculty: Dr. P. Mirunalini, Dr. R. Priyadharsini

Name : Sudharshan Vijayaragavan


Digital Id : 2370007
Course : M.tech Integrated (5 Year) CSE

Learning Outcome:
You will be able to
• Create directories and files
• Differentiate root, Home and Current working directory
• Display directories along with relative paths
• Create soft and hard links
Best Practices: Naming conventions to be followed
Exercise 1: Create the directories as specified and navigate within the
directories as instructed (K3, CO2,1.3.1,1.4.1, 13.3.1)

1. Launch a terminal
Ans: Launched the Terminal

2. Create three directories named letters, reports and assignment under


your home directory
Ans: I/P ~$ mkdir letters reports assignment
I/P ~$ ls
O/P Assignment_2.term assignment letters reports

3. Move to directory letters


Ans: I/P ~$ cd letters
I/P ~/letters$ pwd
O/P /home/user/letters

4. Create two directories named friendly and formal under the letters
directory
Ans: I/P ~/letters$ mkdir friendly formals
I/P ~/letters$ ls
O/P formals friendly

5. Move to directory reports using only one command (directly from letters)
Ans: I/P ~/letters$ cd ../reports
I/P ~/reports$ pwd
O/P /home/user/reports

6. Create three directories called personal, business, and school under the
directory reports (use only one command)
Ans: I/P ~/reports$ mkdir personal business school
I/P ~/reports$ ls
O/P business personal school

7. Create a directory called UNIX under the assignment directory. The


directories in this step should be created without moving from the reports
directory
Ans: I/P ~/reports$ mkdir -p ~/assignment/UNIX
I/P ~/reports$ ls ~/assignment
O/P UNIX

8. Move to your home directory


Ans: I/P ~/reports$ cd ~
I/P ~$ pwd
O/P /home/user

9. Recursively list all the directories you created


Ans: I/P ~$ ls –R
assignment_2.term assignment letters reports

./assignment:
UNIX
./assignment/UNIX:

./letters:
formals friendly

./letters/formals:

./letters/friendly:

./reports:
business personal school

./reports/business:

./reports/personal:

./reports/school:

10. Quit the terminal


Ans: ~$ exit
Exercise 2: Navigate to the directories and create the files as specified and
also create soft links and record your observations. (K3, CO2,1.3.1,1.4.1,
13.3.1)

1. Launch a terminal
Ans: Launched the Terminal

2. Recursively list all the directories you created


Ans: I/P ~$ ls –R
assignment_2.term assignment letters reports

./assignment:
UNIX

./assignment/UNIX:

./letters:
formals friendly

./letters/formals:

./letters/friendly:

./reports:
business personal school

./reports/business:

./reports/personal:

./reports/school:

3. Move to the UNIX directory


Ans: I/P ~$ cd assignment/UNIX
I/P~/assignment/UNIX$ pwd
O/P /home/user/assignment/UNIX

4. Check your current directory


Ans: I/P~/assignment/UNIX$ pwd
O/P /home/user/assignment/UNIX

5. Create a file named hw4 that contains short answers to at least five review
questions in this chapter
Ans: I/P ~/assignment/UNIX$ cat > hw4.txt
1)what is touch command
2)Every time you call a directory or move to it using the absolute path do
you specify the root directory or not.
3)how can you create multiple directories at the same time
4)how can you create a directory without moving out of the present
working directory
5)what is the difference between soft link and hard link
6. Save the file (it should be saved under the UNIX directory).
Ans: I/P ctrl + d
I/P ~/assignment/UNIX$ ls
O/P hw4.txt
7. Move to your home directory
Ans: I/P ~/assignment/UNIX$ cd ~
I/P ~$ pwd
O/P /home/user

8. Print the content of hw4 from your home directory


Ans: I/P ~$ cat assignment/UNIX/hw4.txt
O/P
1)what is touch command
2)Everytime you call a directory or move to it using absolute do you
specify the root directory or not.
3)how can you create multiple directories at the same time
4)how can you create a directory without moving out of the present
working directory
5)what is the difference between soft link and hard link

9. Make a copy of hw4 and call it hw4.bk


Ans: I/P ~$ cp assignment/UNIX/hw4.txt assignment/UNIX/hw4.bk
I/P~$ ls assignment/UNIX
O/P hw4.bk hw4.txt

10. Store it under the same directory where hw4 is stored


Ans: I/P~$ ls assignment/UNIX
O/P hw4.bk hw4.txt

11. From your home directory, check to see if both files (hw4 and hw4.bk)
exist
Ans: I/P~$ ls assignment/UNIX
O/P hw4.bk hw4.txt

12. Move to the UNIX directory


Ans: I/P ~$ cd ~/assignment/UNIX

13. Check your current working directory


Ans: I/P ~/assignment/UNIX$ pwd
O/P /home/user/assignment/UNIX

14. Make a hard link to the hw4 file. The link should be under the UNIX
subdirectory and be called hw4HL
Ans: ~/assignment/UNIX$ ln hw4.txt hw4HL.txt

15. Make a soft link to hw4 called hw4SL and store it under the UNIX
directory
Ans: ~/assignment/UNIX$ ln -s hw4.txt hw4SL.txt

16. Check the inode of hw4, hw4.bk, hw4HL, and hw4SL. Are all the same?
Are all different? Explain how you determined the answer
Ans: I/P ~/assignment/UNIX$ ls -i
O/P 384 hw4.bk 131 hw4.txt 131 hw4HL.txt 513 hw4SL.txt
Here hw4.txt and hw4HL.txt have the same inode number because the hard
link points to the inode of the file rather than the file itself unlinke soft link
Thus except the two above files, all other files have different inode number

17. Use ls command to find the file types of hw4, hw4.bk, hw4HL and
hw4SL. Explain your observation
Ans: I/P ~/assignment/UNIX$ ls –l
O/P
total 4
-rw-r--r-- 1 user user 315 Oct 2 06:04 hw4.bk
-rw-r--r-- 2 user user 315 Oct 2 05:51 hw4.txt
-rw-r--r-- 2 user user 315 Oct 2 05:51 hw4HL.txt
lrwxrwxrwx 1 user user 7 Oct 2 06:33 hw4SL.txt -> hw4.txt

Here all the files are regular files which can be interpreted from the first
letter of the information of the given file except hw4SL.txt which is soft
link which in turn is denoted by the character l.
It can also be interpreted that even the file created by hard link –hw4HL.txt
is considered to be as a regular file.

18. Quit the terminal.


Ans: ~/assignment/UNIX$ exit
Exercise 3. Use Find commands to find the pathnames of the files and
perform the operations as mentioned. (K3, CO2,1.3.1,1.4.1, 13.3.1)

1. Launch a terminal
Ans: Launched the terminal.

2. Create a backup directory in your home directory called backups


Ans:
I/P ~$ mkdir backups
I/P ~$ ls
O/P Assignment_2.term Assignment_2_Ex_3.term assignment backups
hw4.bk letters reports

3. Use the find command to find the pathnames of all of the files (hw4, hw4.bk,
hw4HL, hw4SL) that you created in Exercise 2. All of them should be found
using only one find command. The command must also copy all of them to the
backups directory
Ans:
I/P find -name "hw4*"
O/P
./assignment/UNIX/hw4SL.txt
./assignment/UNIX/hw4HL.txt
./assignment/UNIX/hw4.txt
./assignment/UNIX/hw4.bk

4. Check the number of links and inode number of (hw4, hw4.bk, hw4HL,
hw4SL). Make note of the results.
Ans:
I/P ~$ ls –li
O/P
total 3
642 -rw-r--r-- 1 user user 0 Oct 2 08:46 Assignment_2.term
389 -rw-r--r-- 1 user user 0 Oct 4 16:45 Assignment_2_Ex_3.term
770 drwxr-xr-x 3 user user 3 Oct 2 05:09 assignment
514 drwxr-xr-x 2 user user 2 Oct 2 08:47 backups
768 drwxr-xr-x 4 user user 4 Oct 2 05:00 letters
769 drwxr-xr-x 5 user user 5 Oct 2 05:07 reports

5. Delete the original hw4 file without moving from your home directory
Ans:
I/P ~$ rm assignment/UNIX/hw4.txt
I/P ~$ ls assignment/UNIX
O/P
hw4.bk hw4HL.txt hw4SL.txt

6. Check the existence of hw4, hw4.bk, hw4HL, hw4SL.


Ans:
I/P ~$ ls assignment/UNIX
O/P
hw4.bk hw4HL.txt hw4SL.txt

7. Check the contents of hw4, hw4.bk, hw4HL, hw4SL


Ans:
I/P ~$ cat ~/assignment/UNIX/hw4*
O/P
1)what is touch command
2)Everytime you call a directory or move to it using absolute path what c
commad do you use
3)how can you create multiple directories at the same time
4)how can you create a directory without moving out of the present
working directory
5)what is the difference between soft link and hard link

1)what is touch command


2)Everytime you call a directory or move to it using absolute path what
commad do you use
3)how can you create multiple directories at the same time
4)how can you create a directory without moving out of the present
working directory
5)what is the difference between soft link and hard link

8. Restore hw4 by making a copy of hw4.bk


Ans:
I/P ~$ cp assignment/UNIX/hw4.bk assignment/UNIX/hw4.txt
I/P ~$ ls assignment/UNIX
O/P
hw4.bk hw4.txt hw4HL.txt hw4SL.txt

9. You may have noticed that your soft link (hw4SL) contains garbage. Delete
this file.
Ans:
I/P ~$ rm assignment/UNIX/hw4SL.txt
I/P ~$ ls assignment/UNIX
O/P
hw4.bk hw4.txt hw4HL.txt

10. Make a soft link to hw4 and save it as hw4SL under the same directory as it
was
Ans:
I/P ~$ ln -s hw4.txt hw4SL.txt
I/P ~$ ls assignment/UNIX
O/P
hw4.bk hw4.txt hw4HL.txt

11. List recursively all of your files and directories to confirm all operations.
Ans:
I/P ~$ ls -R
O/P
Assignment_2.term Assignment_2_Ex_3.term assignment backups hw4SL.txt
letters reports

./assignment:
UNIX

./assignment/UNIX:
hw4.bk hw4.txt hw4HL.txt

./backups:

./letters:
formals friendly

./letters/formals:

./letters/friendly:

./reports:
business personal school

./reports/business:
./reports/personal:

./reports/school:

14. Quit the terminal


Ans:
I/P ~$ exit

You might also like