Software engineer in the making week 3.0.. Understanding Linux. Links, Disk Space Efficiency in Linux .

Software engineer in the making week 3.0.. Understanding Linux. Links, Disk Space Efficiency in Linux .

Links...

links serve as pointers to files or directories, allowing users to access them conveniently.

Before we delve deep into Links do you know about Inode ?

We'll talk about two basic Link types Soft links and hard links both used to establish connections between files or directories but with some uniqueness.

Soft Links : A soft link, also known as a symbolic link , is a special type of file that serves as a pointer to another file or directory. It acts as a shortcut or reference to the original file, enabling easy access from different locations within the file system.

Key characteristics of soft links include:

1. Soft links can point to files or directories located on the same file system or even on different file systems.

2. They can link to both absolute and relative paths.

3. Soft links retain their functionality even if the original file or directory is moved or renamed.

4. Deleting a soft link does not affect the original file or directory.

5 . Deleting the Parents file makes the soft Links useless.

Hard Links:

A hard link is a direct link to a file or directory, establishing multiple paths to access the same underlying data. Unlike soft links, hard links are not separate files; they are additional directory entries pointing to the same inode (data structure representing a file) as the original file.

Key characteristics of hard links include:

1. Hard links can only be created for files, not directories.

2. They are limited to linking files within the same file system.

3. All hard links associated with a file are essentially equal, without any distinction of the "original" file.

4. If the original file is deleted, the hard links remain intact, and the data is preserved until all hard links are deleted.

Differences between Soft Links and Hard Links:

1. Structure: Soft links are separate files with their own inode, while hard links share the same inode as the original file.

2. File Types: Soft links can point to both files and directories, whereas hard links can only link to files.

3. Cross-File System Linking: Soft links can span across different file systems, whereas hard links are limited to a single file system.

Practical Example how to Hard link and Short Link a File X Directory.

Lets create a directory called Link then make four text files link1.txt ...

lets create soft links for Link1.txt

Using this command ln -s /path/to/original-file /path/to/soft-link

A represents the short link command that tells the computer to create a short link B represents the Parent file ( link1.txt ) C represents the soft-link destination which here is softlink-link

Lets create a Hard Link for same file. This time we remove the -s

ln /home/user/documents/myfile.txt /home/user/hard-link

That's it for now.. ill write on more use case of this command in the future and inode number.