Questions tagged [hard-link]

A hard link is file system entry that associates a name with another file on a file system.

A hard link is file system entry that associates a name with another file on a file system.

247 questions
201
votes
20 answers

Is there an easy way to replace duplicate files with hardlinks?

I'm looking for an easy way (a command or series of commands, probably involving find) to find duplicate files in two directories, and replace the files in one directory with hardlinks of the files in the other directory. Here's the situation: This…
Josh
  • 8,311
  • 12
  • 54
  • 73
155
votes
7 answers

Why are hard links to directories not allowed in UNIX/Linux?

I read in text books that Unix/Linux doesn't allow hard links to directories but does allow soft links. Is it because, when we have cycles and if we create hard links, and after some time we delete the original file, it will point to some garbage…
user3539
  • 4,288
  • 9
  • 34
  • 44
94
votes
7 answers

Why do hard links exist?

I know what hard links are, but why would I use them? What is the utility of a hard link?
Luc M
  • 4,025
  • 5
  • 30
  • 29
93
votes
6 answers

How to copy a directory recursively using hardlinks for each file

I want to create a "copy" of a directory tree where each file is a hardlink to the original file Example: I have a directory structure: dirA/ dirA/file1 dirA/x/ dirA/x/file2 dirA/y/ dirA/y/file3 Here is the expected result, a "copy" of the…
Gudmundur Orn
  • 1,981
  • 1
  • 11
  • 9
86
votes
3 answers

What happens when you delete a hard link?

If you do rm myFile where myFile is a hard link, what happens?
trusktr
  • 4,035
  • 7
  • 29
  • 34
84
votes
7 answers

Determining if a file is a hard link or symbolic link?

I'm creating a shell script that would take a filename/path to a file and determine if the file is a symbolic link or a hard link. The only thing is, I don't know how to see if they are a hard link. I created 2 files, one a hard link and one a…
k-Rocker
  • 1,375
  • 2
  • 12
  • 9
68
votes
1 answer

How to find all hard links to a given file?

How can we find all hard links to a given file? I.e., find all other hard links to the same file, given a hard link? Does filesystem keep track of the hard links to a file? The inode of a file only stores the number of hard links to the file, but…
Tim
  • 98,580
  • 191
  • 570
  • 977
65
votes
10 answers

What is the difference between symbolic and hard links?

When would you use one over the other?
ripper234
  • 31,063
  • 43
  • 82
  • 90
54
votes
2 answers

Why is '.' a hard link in Unix?

I've seen many explanations for why the link count for an empty directory in Unix based OSes is 2 instead of 1. They all say that it's because of the '.' directory, which every directory has pointing back to itself. I understand why having some…
Joseph Garvin
  • 819
  • 7
  • 10
50
votes
6 answers

How to copy directories with preserving hardlinks?

How to move directories that have files in common from one to another partition ? Let's assume we have partition mounted on /mnt/X with directories sharing files with hardlinks. How to move such directories to another partition , let it be /mnt/Y…
Grzegorz Wierzowiecki
  • 13,865
  • 23
  • 89
  • 137
47
votes
4 answers

What's the difference between hard links and copied files?

My understanding is that hard links include a copy of the original file, and that I could delete a hard-linked file in one location, and it would still exist in the other location. If that's the case, why would I want to use hard links at all? Why…
Mike B
  • 8,769
  • 24
  • 70
  • 96
47
votes
9 answers

Use cases for hardlinks?

In what situations would one want to use a hard-link rather than a soft-link? I personally have never run across a situation where I'd want to use a hard-link over a soft-link, and the only use-case I've come across when searching the web is…
Matthew Cline
  • 3,265
  • 4
  • 24
  • 38
39
votes
5 answers

Can a file be retrieved by its inode?

I ran following commands in the order specified: $ln a b $ls -i a b 523669 a 523669 b $rm -f a $ls -i b 523669 b I concluded from this test that the command rm actually removes only the filename (a in this test) instead of the file, as the inode…
user43312
  • 951
  • 2
  • 12
  • 20
38
votes
8 answers

What is the difference between a hard link and a file?

A hard link is defined as a pointer to an inode. A soft link, also known as a symbolic link, is defined as an independent file pointing to another link without the restrictions of hard links. What is the difference between a file and a hard link? A…
36
votes
7 answers

Replace file with hard link to /dev/null

I'm running an application that writes to log.txt. The app was updated to a new version, making the supported plugins no longer compatible. It forces an enormous amount of errors into log.txt and does not seem to support writing to a different log…
MALON
  • 443
  • 1
  • 4
  • 6
1
2 3
16 17