In: Computer Science
Go to your “Documents” directory;
a) Create a file “file1” with the text “hello” in it; Provide command and screenshot.
b) Create a hard link named “file2” linked to “file1”;
c) Create a soft link named “soft1” linked to “file1”; create another soft link named “soft2” linked to “file2”.
d) View information of the 4 files (what command should you use to produce output) – how do you verify which file is a hard link and which file is a soft link?
e) Use a text editor (Nano or VIM) to edit “soft2”: change “hello” to “hello, world”. Now, what is the content in each of the files? Provide screenshots. Are they all the same? If yes, why?
f) How do you remove all these hard and soft links? Apply the command and provide screenshots of the removal results.
Below is the solution:
a) create a file1 with text hello in it
$echo 'hello'>file1
b) create hard link of file1 of file2
$ln -v file1 file2
file2 => file1
c) create soft link soft1 of file1
$ln -s file1 soft1
create soft link soft2 of file2
$ ln -s file2 soft2
d) to view information of 4 file
$ls -l
It will give the all file which is softlink and hardlink.
-rw-r--r--@ 2 John staff 6 Sep 8 18:56 file1
-rw-r--r--@ 2 John staff 6 Sep 8 18:56 file2
lrwxr-xr-x 1 John staff 5 Sep 8 19:02 soft1 -> file1
lrwxr-xr-x 1 John staff 5 Sep 8 19:07 soft2 -> file2
The files that start with l are your symbolic(softlink) link files.
e) $ vi soft2
this command will open the file in vi editor click i to insert the
text and edit the text hello to hello, world
and now press ESC and type :wq ( to save and quit from the vi
editor).
after that check the each file of the content will be changed
beacuse of softlink.
f) to remove the softlink use command
$unlink soft1
$unlink soft2
$ls -l
-rw-r--r--@ 2 John staff 12 Sep 8 19:15 file1
-rw-r--r--@ 2 John staff 12 Sep 8 19:15 file2
See the all sybolink link will removed
Now remove the hard link
$rm file2
$ ls -l
-rw-r--r--@ 1 John staff 12 Sep 8 19:15 file1