1833051 Members
2387 Online
110049 Solutions
New Discussion

Link two Directories

 
SOLVED
Go to solution
George Nikoloudis_1
Frequent Advisor

Link two Directories

Hello Experts
Can you tell me how can I link two directories?
e.g.

/mnt1a/george/data->mnt2a/root/data
12 REPLIES 12
Deepak Extross
Honored Contributor

Re: Link two Directories

Hi,

ln -s


Frederic Sevestre
Honored Contributor

Re: Link two Directories

Hi,

ln -s /mnt2a/root/data /mnt1a/george/data

regards
Fr??d??ric
Crime doesn't pay...does that mean that my job is a crime ?
Etienne Holm
Frequent Advisor

Re: Link two Directories

Hi
go to the dir you wnat the linked dir to be
cd mnt2a/root
then do
ln -s /mnt1a/george/data data
Steven Sim Kok Leong
Honored Contributor
Solution

Re: Link two Directories

Hi,

Assuming that mnt2a/root/data currently contains the data and /mnt1a/george/data is the link,

If you want a hard-link,

# ln /mnt2a/root/data /mnt1a/george/data

If you want a soft-link,

# ln -s /mnt2a/root/data /mnt1a/george/data

Hope this helps. Regards.

Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
federico_3
Honored Contributor

Re: Link two Directories

to get /mnt1a/george/data-> /mnt2a/root/data
type:

ln -s /mnt2a/root/data /mnt1a/george/data
Darrell Allen
Honored Contributor

Re: Link two Directories

Hi George,

One minor point to add: If /mnt1a/george/data already exists, the ln (with or without -s) command will fail.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Roger Baptiste
Honored Contributor

Re: Link two Directories

<mnt2a/root/data >>

cd /mnt1a/george
ll data (just to confirm there is no such directory existing; if it is move or remove it)
ln -s data /mnt2a/root/data

Another point, do not worry about the permissions of /mnt1a/george/data . Irrespective of what it is the permission of the actual directory will be counted during access.

HTH
raj
Take it easy.
Victor_5
Trusted Contributor

Re: Link two Directories

Regarding link, there are hard link and symbolic link, for directory link, you only can use the later one.

Use the ln command with -s to create a symbolic link. The first argument identifies the existing file that you wish to link to. Additional arguments specify the path names of the symbolic links you wish to create to the existing file.

In your case, it is
ln -s /mnt2a/root/date /mnt1a/george/date

Shawn
Sanjay_6
Honored Contributor

Re: Link two Directories

Hi George,

Try,

ln -s /mnt2a/root/data /mnt1a/george/data

hope this helps.

Regds
Darrell Allen
Honored Contributor

Re: Link two Directories

Hi all,

My earlier reply definitely was not a good one. Shawn points out correctly that ln (without -s) will fail if the source is a directory. You must use ln -s on directories.

To clarify (hopefully) the point I was trying to make earlier:
ln -s will fail if the destination exists and is a file. ln -s will succeed if the destination exists and is a directory however the link will be created subordinate to the destination directory. Examples:

# ll
total 0
drwxr-xr-x 2 root sys 96 Dec 6 11:39 d
-rw-r--r-- 1 root sys 0 Dec 6 11:40 e
drwxr-xr-x 2 root sys 96 Dec 6 11:40 f
# ln d e
ln: directory
# ln d f
ln: directory
# ln -s d e
ln: e exists
# ln -s d f
# ll
total 0
drwxr-xr-x 2 root sys 96 Dec 6 11:39 d
-rw-r--r-- 1 root sys 0 Dec 6 11:40 e
drwxr-xr-x 2 root sys 96 Dec 6 11:40 f
# ll f
lrwxr-xr-x 1 root sys 1 Dec 6 11:40 d -> d

Sorry for my earlier poor post. I added confusion to the issue instead of clarification.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Kurtkarl
Frequent Advisor

Re: Link two Directories

hi,

for hard link
ln / /
for soft (symbolic) link
ln -s / /

note: ln does not create hard links across
filesystems.
joey
Just starting to learn thru this forum
Ron Freeland
Occasional Advisor

Re: Link two Directories

Hello

The manpage for ln shows as if 2 directories can be hard linked, but in the manpage it states: "The ln command does not permit hard links to a directory."
To link directories the -s option must be used.