On Mon, Aug 06, 2001 at 02:30:54PM +0200, n.briggs@canon-europa.com wrote:
Paul,
This is what I think, I believe that unlink removes symbolic links not files. If I use the rm command I am in danger of removing the directory that the link (I want to remove points too). Removing the files is not what I want to do. I just want to remove a symbolic link.
No. <background> There are two types of link on a UNIX filesystem - hard and soft. Soft links are simple files which have a particular attribute set in their directory entries, saying that the contents of the file should be considered to be a pointer to another filename. Hard links are where you have two or more filesystem 'filename' entries which point to the same bit of disk for the 'contents' of the file. On DOS filesystems, this is considered to be an error, but on Unix, it's valid. You will probably find that some programs in /bin or /usr/bin (e.g. gzip/gunzip) are hard links. You can find this out by asking ls to report the inode numbers - any two files which have the same inode number are hard links. Now, when you delete a file, all you actually do is remove its directory entry. The inode (basically the bit of disk where the file is stored) keeps track of the number of directory entries (hard links) it has, and when it reaches 0, the bit of disk is deallocated by the operating system. This is the reason why the programming function is called 'unlink' - it removes the hard link. rm itself will call unlink to remove files. Multiple hard links are seldom used by anyone except the operating system builder - don't use them unless you *really* know what you're doing (and with all due respect, you sound like you don't... :-) ) This description is a bit simplified and probably contains some inaccuracies, but it's close enough to real life to be relevant... </background> So, the command you want is rm. -- David Smith Tel: +44 (0)1454 462380 (direct) STMicroelectronics Fax: +44 (0)1454 617910 1000 Aztec West TINA (ST only): (065) 2380 Almondsbury Home: 01454 616963 BRISTOL Mobile: 07932 642724 BS32 4SQ Work Email: Dave.Smith@st.com Home Email: David.Smith@ds-electronics.co.uk
Dave Smith wrote:
There are two types of link on a UNIX filesystem - hard and soft.
Soft links are simple files which have a particular attribute set in their directory entries, saying that the contents of the file should be considered to be a pointer to another filename.
Hard links are where you have two or more filesystem 'filename' entries which point to the same bit of disk for the 'contents' of the file. On DOS filesystems, this is considered to be an error, but on Unix, it's valid. You will probably find that some programs in /bin or /usr/bin (e.g. gzip/gunzip) are hard links. You can find this out by asking ls to report the inode numbers - any two files which have the same inode number are hard links.
"ls" will also show you explicitly whether a file is a soft link and what it links to. But I don't know of any way, other than searching, of determining whether a particular file has more than one link, hard or soft, to it.
Now, when you delete a file, all you actually do is remove its directory entry. The inode (basically the bit of disk where the file is stored) keeps track of the number of directory entries (hard links) it has, and when it reaches 0, the bit of disk is deallocated by the operating system. This is the reason why the programming function is called 'unlink' - it removes the hard link. rm itself will call unlink to remove files.
Multiple hard links are seldom used by anyone except the operating system builder - don't use them unless you *really* know what you're doing (and with all due respect, you sound like you don't... :-) )
Hard links historically were available long before soft links were. I don't know why people still use hard links. Soft links can create circular or undefined references, though, and "cd"ing to a soft-linked directory has the sometimes surprising side effect of changing the parent directory.
This description is a bit simplified and probably contains some inaccuracies, but it's close enough to real life to be relevant...
Yes. Paul
On Monday 06 August 2001 18:45, Paul Abrahams wrote:
"ls" will also show you explicitly whether a file is a soft link and what it links to. But I don't know of any way, other than searching, of determining whether a particular file has more than one link, hard or soft, to it.
If you do a ls -l, the first number following the permissions is the number of hard links a file has. There's no way of determining the number of soft links, however, short of searching the entire file system.
On Mon, Aug 06, 2001 at 12:45:24PM -0400, abrahams@acm.org wrote:
Dave Smith wrote: "ls" will also show you explicitly whether a file is a soft link and what it links to. But I don't know of any way, other than searching, of determining whether a particular file has more than one link, hard or soft, to it.
man ls: ls -l (the long list) prints its output as follows for the POSIX locale: -rwxrwxrwx+ 1 smith dev 10876 May 16 9:42 part2 [snip] The number, in this case 1, indicates the number of links to file part2 In this case, the man page refers to hard links only. All files >1 have hard links.
Hard links historically were available long before soft links were. I don't know why people still use hard links. Soft links can create circular or undefined references, though, and "cd"ing to a soft-linked directory has the sometimes surprising side effect of changing the parent directory.
Also, directories cannot be hard linked, to prevent circular references. Otherwise, commands like 'pwd' would get very confused indeed - which one is up? The only advantages I can think of for hard links are: One less inode used. Less disk space. Faster - no dereferencing necessary. -- David Smith Tel: +44 (0)1454 462380 (direct) STMicroelectronics Fax: +44 (0)1454 617910 1000 Aztec West TINA (ST only): (065) 2380 Almondsbury Home: 01454 616963 BRISTOL Mobile: 07932 642724 BS32 4SQ Work Email: Dave.Smith@st.com Home Email: David.Smith@ds-electronics.co.uk
participants (3)
-
Anders Johansson
-
Dave Smith
-
Paul Abrahams