Are my Linux symbolic links acting correctly?
Posted
by Andy Castles
on Super User
See other posts from Super User
or by Andy Castles
Published on 2010-06-11T12:57:49Z
Indexed on
2010/06/11
14:03 UTC
Read the original article
Hit count: 308
Hi all
I've been using Linux on and off for the last 15 years and today I came across something in bash that surprised me.
Setup the following directory structure:
$ cd /tmp
$ mkdir /tmp/symlinktest
$ mkdir /tmp/symlinktest/dir
$ mkdir /tmp/symlinktarget
Now create two sym links in symlinktest pointing to symlinktarget:
$ cd /tmp/symlinktest
$ ln -s ../symlinktarget Asym
$ ln -s ../symlinktarget Bsym
Now, in bash, the following tab completion does strange things. Type the following:
$ cd dir
$ cd ../A[TAB]
Pressing the tab key above completes the line to:
$ cd ../Asym/
as I expected. Now press enter to change into Asym and type:
$ cd ../B[TAB]
This time pressing the tab key completes the link to:
$ cd ../Bsym[space]
Note that there is now a space after the Bsym and there is no trailing slash.
My question is, why when changing from the physical directory "dir" to Asym it recognises that Asym is a link to a directory, but when changing from one sym link to another, it doesn't recognise that it's a link to a directory?
In addition, if I try to create a new file within Asym, I get an error message:
$ cd /tmp/symlinktest/Asym
$ cat hello > ../Bsym/file.txt
-bash: ../Bsym/file.txt: No such file or directory
I always thought that symlinks were mostly transparent except to programs that need to manipulate them. Is this normal behaviour?
Many thanks,
Andy
© Super User or respective owner