Introduction To UNIX/Linux and The Internet: Filesystem Links
Introduction To UNIX/Linux and The Internet: Filesystem Links
ULI101
Filesystem Links
Hard Links
and
Soft or Symbolic Links
Hard Links
●
Hard link is a reference to the physical data on a
filesystem
●
All named files are hard links
●
More than one name can be associated with the
same physical data
●
Hard link can only refer to data that exists on the
same file system
●
©2005 Raymodn.chan for ULI101
6
ln myfile link-name
©2005 Raymodn.chan for ULI101
7
Removing a link
When a file has more than one link, you can
remove any one link and still be able to access the
file through the remaining links.
[uli@seneca links] ls -li
38753 -rw-rw-r-- 3 uli uli 29 Oct 29 08:47 myfile
38753 -rw-rw-r-- 3 uli uli 29 Oct 29 08:47 mylink
38753 -rw-rw-r-- 3 uli uli 29 Oct 29 08:47 newlink
[uli@seneca links] rm mylink
[uli@seneca links] ls -li
38753 -rw-rw-r-- 2 uli uli 29 Oct 29 08:47 myfile
38753 -rw-rw-r-- 2 uli uli 29 Oct 29 08:47 newlink
[uli@seneca links] rm myfile
[uli@seneca links] ls -li
38753 -rw-rw-r-- 1 uli uli 29 Oct 29 08:47 newlink
©2005 Raymodn.chan for ULI101
11
Links
©2005 Raymodn.chan for ULI101
13
./ica101:
44309 -rw-rw-r-- 1 uli uli 45 Oct 29 11:15 to_do
./ios110:
44407 -rw-rw-r-- 1 uli uli 49 Oct 29 11:16 to_do
./uli101:
38772 -rw-rw-r-- 1 uli uli 51 Oct 29 11:14 to_do
©2005 Raymodn.chan for ULI101
14
[uli@seneca courses] ls -i
38767 ica101 38768 ios110 38762 uli101
[uli@seneca courses] mkdir to_do
38767 ica101 38768 ios110 38769 to_do 38762 uli101
Create links in the to_do directory to the
to_do file in each course's directory
Recap
●
Use “ln” to create hard links
●
Files with the same i-node number refer to the
same physical file
●
Use “ls -i” to display the file's i-node number and
link counter
●
Use “rm filename” to remove a hard link
●
A physical file will be deleted from the file
system when its link counter drops to zero,
©2005 Raymodn.chan for ULI101
18
Symbolic Links
Also Know As (a.k.a.): Soft links or Symlinks
●
Symbolic link is an indirect pointer to a file – a
pointer to the hard link to the file
●
You can create a symbolic link to a directory
●
A symbolic link can point to a file on a different
filesystem
●
A symbolic link can point to a nonexistent file
©2005 Raymodn.chan for ULI101
19
Directory Listing
●
To display the contents in a directory, we normally
use the command “ls -l directory_name”
●
Compare the following to commands
[uli@seneca week8]$ ls -l mydir
lrwxrwxrwx 1 uli uli 7 Oct 29 15:41 mydir -> courses
Reference
●
Hard Links
– http://en.wikipedia.org/wiki/Hard_link
●
Symbolic Links
– http://en.wikipedia.org/wiki/Symbolic_link
●
I-nodes
– http://www.cse.unsw.edu.au/~neilb/oss/linux-commentary/vfs-7.html
– http://en.wikipedia.org/wiki/Inode
©2005 Raymodn.chan for ULI101
27
More Q & A
●
How do you create the first hard link to a file?
●
How do you create the 2nd (and up) hard link to a
file?
●
What is the purpose of a link counter?
●
Where can you get the link counter of a file?
●
How do you create a soft link to a file?
●
Does a soft link file has the same i-node number
©2005 Raymodn.chan for ULI101
29
More Q & A
●
How do you remove a hard link?
●
How do you delete a physical file with multiple
links?
●
How do you create a symbolic link to a file?
●
How do you create a symbolic link to a directory?
●
Could you create a symbolic to a file which does
not exist?
©2005 Raymodn.chan for ULI101
30
More Q & A
●
How do you display the contents of a regular
directory?
●
How do you display the contents of a symbolic
link to a regular directory?
●
How do you display the status information of a
regular directory?
●
More Q & A ?
©2005 Raymodn.chan for ULI101