Alias Physical Files

Linux allows you to associate more than one name to the same physical

file. This feature is useful, for instance, when you need to refer to

the same physical file from different directories. This week I will

explain how to create file links using the ln command.

The ln command defines a new name - commonly called a link - for an

existing file. In the following example, the user defines a new link

called "january" for the file reports01_01:

$ln reports01_01 january

The ln command takes two parameters, the first being the original

filenames and the second the new associated name. If you list the

current directory's files, you will see a new item added -- the link



reports01_01 january

Remember though, only one physical file resides in the directory.

Adding a link doesn't create a new file, it merely creates an alias.

It's possible to associate more than one link per file. The

following example issustrates associating a new link with the file


$ln reports01_01 inventory

As expected, the ls command now shows three different files in the

current directory, two of which are the previously defined links:


reports01_01 january inventory

To find out the number of links associated with a file, type the ls

command with the -l option. This option provides additional information

about a file such as permissions, the number of associated links, the

owner, the size, and modification date. However, this option still

doesn't reveal the names linked to the same file. To see the

associated links, use the -i option. This option displays the file's

inode - a unique identification number Linux assigns to each physical

file. If two filenames have the same inode number, then they are linked

to the same physical file. For example:

$ls -i january inventory

4577 january 4577 inventory

To delete a file, you have to remove all of its associated links. So

long as one associated link remains, the file isn't deleted; even if

the original filename has been removed, the physical file remains

intact. In the following example, the user employs the rm command to

remove the file reports01_01. However, since this file has two other

associated links, it still can be accessed through them:

$rm reports01_01

$cat january

bulbs 12

mice 56

ITWorld DealPost: The best in tech deals and discounts.
Shop Tech Products at Amazon