Unix Shell - Symbolic links to directories: slash or no slash?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2006 > Symbolic links to directories: slash or no slash?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Symbolic links to directories: slash or no slash?
Tristan Miller

2006-02-26, 10:19 am

Greetings.

Is there any effective difference between the following two commands,
assuming /foo/bar is a directory?

$ ln -s /foo/bar

$ ln -s /foo/bar/

When I do ls -l on the former, it shows

lrwxrwxrwx 1 root root 16 2006-02-24 16:17 bar -> /foo/bar/

and on the latter, it shows

lrwxrwxrwx 1 root root 16 2006-02-24 16:17 bar -> /foo/bar//

Does this make any real difference when it comes to interactive or batch
shell use, or is it purely cosmetic?

In case it matters, I use bash on GNU/Linux.

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Chris F.A. Johnson

2006-02-26, 10:19 am

On 2006-02-24, Tristan Miller wrote:
> Greetings.
>
> Is there any effective difference between the following two commands,
> assuming /foo/bar is a directory?
>
> $ ln -s /foo/bar
>
> $ ln -s /foo/bar/
>
> When I do ls -l on the former, it shows
>
> lrwxrwxrwx 1 root root 16 2006-02-24 16:17 bar -> /foo/bar/
>
> and on the latter, it shows
>
> lrwxrwxrwx 1 root root 16 2006-02-24 16:17 bar -> /foo/bar//
>
> Does this make any real difference when it comes to interactive or batch
> shell use, or is it purely cosmetic?
>
> In case it matters, I use bash on GNU/Linux.


A symbolic link stores the string you give it as the target of the
link. If you add a trailing slash, that will be added to the
target.

The final slash is because you have an alias for ls which includes
-F. Try "unalias ls", then list them.


--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
Michael Paoli

2006-02-26, 10:19 am

Tristan Miller wrote:
> Is there any effective difference between the following two commands,
> assuming /foo/bar is a directory?
> $ ln -s /foo/bar
> $ ln -s /foo/bar/
>
> Does this make any real difference when it comes to interactive or batch
> shell use, or is it purely cosmetic?


In some circumstances, it will make a difference, e.g.:

$ mkdir dir
$ ln -s dir noslash
$ ln -s dir/ slash
$ ls -ld *slash
lrwxrwxrwx 1 michael users 3 Feb 24 23:14 noslash -> dir
lrwxrwxrwx 1 michael users 4 Feb 24 23:14 slash -> dir/
$ (cd slash && echo OK)
OK
$ (cd noslash && echo OK)
OK
$ rmdir dir
$ echo file > dir
$ cat noslash
file
$ cat slash
cat: slash: Not a directory
$

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com