Trailing slash in symbolic link

I recently noticed something strange when creating a symbolic link to a directory:

$ ln -s foo_dir/ slink_to_dir
$ ls -l
drwxrwxr-x 2 ashwin ashwin 4.0K 2016-10-05 21:37 foo_dir/
lrwxrwxrwx 1 ashwin ashwin    7 2016-10-10 21:47 slink_to_dir -> foo_dir//

Notice the double slash (one extra slash) in the destination of the symbolic link.

In fact, you can add multiple slashes and they all show up with one extra slash:

$ ln -s foo_dir/// slink_to_dir
$ ls -l
drwxrwxr-x 2 ashwin ashwin 4.0K 2016-10-05 21:37 foo_dir/
lrwxrwxrwx 1 ashwin ashwin    7 2016-10-10 21:47 slink_to_dir -> foo_dir////

Turns out that this is the standard working of the ln command. If you are pedantic, you can keep it clean by never specifying a slash when creating a symbolic link using ln:

$ ln -s foo_dir slink_to_dir

Anyway, even if you use the extra slashes they have no effect either since Unix (and Linux) allow and ignore the multiple slashes in a path.

Tried with: Ubuntu 16.04

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s