Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a doubt regarding what are the differences when we make a new file using touch command and when we make a new hard-link to a file. It would be nice for me if you can explain me it in detail.

share|improve this question

migrated from May 3 '11 at 14:40

This question came from our site for professional and enthusiast programmers.

man ln and man touch. These commands are not related in any way. – sehe May 3 '11 at 14:00

touch (with only a name as the argument) simply creates a new (empty) file. That file has no relation to any other file, it's stand-alone.

Creating a new hard link (using ln without the -s switch) will create a second directory entry for the same "file". This means that you now have two directory entries (each representing a name) that access the same content: if you append to one of them, then that change is represented in the other. Deleting one, will keep the other one alive (because deleting a "file" per default only deletes the directory entry. Only if that was the last one, will the "real" content be deleted).

share|improve this answer

'touch' creates a new file, while a hard link is just another name for the same file.

Try it with the following commands:

touch file1.txt
touch file2.txt
touch file3.txt
ln file3.txt file4.txt
echo "Hello world!" >> file1.txt
echo "Hello world!" >> file2.txt
echo "Hello world!" >> file3.txt
echo "Hello world!" >> file4.txt

Check the contents: file1.txt and file2.txt should both contain one line. file3.txt and file4.txt both contain two lines.

share|improve this answer

touch will create a brand new file while ln will link to an EXISTING file

share|improve this answer

man ln and man touch. These commands are not related in any way.

Links don't allocate a new inode, other entries do. You can find out the inode number for files using

 ls -i

(or ls -li etc).

To find a file with a given inode number:

 find -inum 98398

Inodes are unique only withing a filesystem Hardlinking is only possible within a single filesystem

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.