Sponsored Content
Top Forums UNIX for Dummies Questions & Answers links: (soft, hard? symbolic??) inode Post 20925 by hugo_perez on Tuesday 7th of May 2002 05:06:32 PM
Old 05-07-2002
You have an explanation about hard links and soft links wiyh directories.

An explanation with files could be:

A file is referenced in the system by a i-node number, when you create a
file, the OS assign an i-node number to the file_name.
example:

a- create a file "pp"
echo "hard_soft_link_inode?" >> pp

b- list the file
ls -l pp
-rw-r--r-- 1 root system 22 May 07 18:39 pp
The number 1 is the number of hard links that the file has.

c- view the i-node number of pp assigned by the system:
ls -i pp
24 pp
the 24 number is the i-node number


d- when you make a hard link, the count of i-nodes of the file
is increased by 1 (and when you unlink the the hard link the number
is decreased by 1):

ln pp hard_link_to_pp
ln pp hard_link2_to_pp
ls -l pp
-rw-r--r-- 3 root system 22 May 07 18:39 pp

ls -i hard_link_to_pp
24 hard_link_to_pp

ls -i hard_link2_to_pp
24 hard_link_to_pp


if you remove the original file (you can access the file content by the
hard link)
rm pp

cat hard_link_to_pp
hard_soft_link_inode?

when you use the unlink command the i-node count decrease by 1:
unlink hard_link_to_pp
ls -l hard_link2_to_pp
-rw-r--r-- 1 root system 22 May 07 18:39 hard_link2_to_pp

if you unlink/rm again you lost the file.

Note: I prefer to use the unlink command over a hard link over the rm command.


The soft link is a pointer that could be point to nothing, to a file in the
same FS, or to a file in other FS (recommended use). To create a soft link
you need to use the "-s" flag of the "ln command".

A common use of hard links is some scripts in the rcX.d (X=1,2,3,S) that
are associated to files in the init.d directory. Use the "ls -i" in rc3.d and in the
init.d directories.

Good luck with your test, and sorry with my poor english.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

links.... soft or hard.. not sure?

hi, i am in a directory, have 2 files as below then do a ls -l gives the below lrwxrwxrwx 1 root system 23 Mar 08 2001 filea -> /adir/filea lrwxrwxrwx 1 root system 23 Mar 08 2001 filea -> /adir/fileb now, when i do a cd /adir, the system said, adir not... (5 Replies)
Discussion started by: yls177
5 Replies

2. Programming

Ignoring symbolic/hard links while scanning through a directory

Hi, I am writing a unix system utility that is supposed to scan through a directory, collecting information about the files and subdirectories. That part is going well. The tricky part is that some files in the directory are hard links or symbolic links. I am supposed to IGNORE these links.... (4 Replies)
Discussion started by: Yifan_Guo
4 Replies

3. Shell Programming and Scripting

using find to locate hard and soft links with tar

I am digging for certain types of files in the current directory and all its sub-directories and archiving them with the following code: #! /usr/bin/ksh Archive=`date +%Y_%m_%d_%T` find . -type f \( -name \*\.ksh -o -name \*\.sql -o -name \*\.ini \) -print|xargs tar -cf... (4 Replies)
Discussion started by: manthasirisha
4 Replies

4. UNIX for Dummies Questions & Answers

ZIP a soft / symbolic link target

Hey, How can one ZIP the target of a soft/symbolic link in unix (if dodag@ is a symbolic link for the path car/reno/*.*, how can I zip car/reno/*.*, with using only dodag as my reference)? Thxnk you. (1 Reply)
Discussion started by: galz
1 Replies

5. UNIX for Dummies Questions & Answers

Deleting Symbolic and/or Hard links

From what I understand a symbolic link is alot like a shortcut where it points to another file. if the original file is deleted the symbolic link is rendered useless but a symbolic link can be deleted without any problem. A hard link is like a copy of the file itself but pointing to the same... (3 Replies)
Discussion started by: cue
3 Replies

6. Windows & DOS: Issues & Discussions

gVim on windows 7 64 constantly overwrites symbolic and even hard links

I use sugarsync to sync my vimrc across computers. I keep the _vimrc file in a syncing folder and in my home folder, I have a symbolic link ~\_vimrc pointing to ~\Synced Docs\_vimrc. On my mac I have a .vimrc symbolic link pointing at the _vimrc file. On the pc side, every time I open the _vimrc... (3 Replies)
Discussion started by: dp88
3 Replies

7. Solaris

Hard Links and Soft or Sym links

When loooking at files in a directory using ls, how can I tell if I have a hard link or soft link? (11 Replies)
Discussion started by: Harleyrci
11 Replies

8. AIX

List all the soft links and hard links

Hi I'm logged in as root in an aix box Which command will list all the soft links and hard links present in the server ? (2 Replies)
Discussion started by: newtoaixos
2 Replies

9. UNIX for Dummies Questions & Answers

Simple example for soft and hard links

Hai, give me a simple example for soft and hard links. this will work for soft link ?? ln -s (2 Replies)
Discussion started by: Ramesh M
2 Replies

10. Shell Programming and Scripting

Timestamp change for hard and soft links

Hi team, i am writing a purge script to delete softlinks and hardlinks on linux system which are 3/10/30 days old. To test the script i need to create links with old timestamp, i am able to cange timestamp for files but not for links. i tried touch -h option but this option is not available on... (1 Reply)
Discussion started by: Satyak
1 Replies
LN(1)							      General Commands Manual							     LN(1)

NAME
ln - make links SYNOPSIS
ln [ -s ] sourcename [ targetname ] ln [ -s ] sourcename1 sourcename2 [ sourcename3 ... ] targetdirectory DESCRIPTION
A link is a directory entry referring to a file; the same file (together with its size, all its protection information, etc.) may have several links to it. There are two kinds of links: hard links and symbolic links. By default ln makes hard links. A hard link to a file is indistinguishable from the original directory entry; any changes to a file are effective independent of the name used to reference the file. Hard links may not span file systems and may not refer to directories. The -s option causes ln to create symbolic links. A symbolic link contains the name of the file to which it is linked. The referenced file is used when an open(2) operation is performed on the link. A stat(2) on a symbolic link will return the linked-to file; an lstat(2) must be done to obtain information about the link. The readlink(2) call may be used to read the contents of a symbolic link. Symbolic links may span file systems and may refer to directories. Given one or two arguments, ln creates a link to an existing file sourcename. If targetname is given, the link has that name; targetname may also be a directory in which to place the link; otherwise it is placed in the current directory. If only the directory is specified, the link will be made to the last component of sourcename. Given more than two arguments, ln makes links in targetdirectory to all the named source files. The links made will have the same name as the files being linked to. SEE ALSO
rm(1), cp(1), mv(1), link(2), readlink(2), stat(2), symlink(2) 4th Berkeley Distribution April 10, 1986 LN(1)
All times are GMT -4. The time now is 04:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy