51

Possible Duplicate:
How linux handles multiple path separators (/home////username///file)

Do cd dir/subdir/ and cd dir/subdir// mean the same in UNIX?

Will the later work out? Else does it have any special meaning?

cd, mv, ls or any command for that sake.

59

Actually it means nothing and is ignored.

This often happens when output from multiple places is combined and it isn't clear who's job it is to add the slashes, so both parties do it and you end up with two of them. Semantically in the case of a directory path is has no meaning and will be ignored by most programs.

There are other situations in the unix world where they have meaning. Sometimes at the start of a path they could trigger a search for a samba path instead of a local file system path, or after a protocol in nfs they can indicate a hostname, however particularly in the case of a trailing slash like you gave as an example, it shouldn't matter much.

For the sake of your sanity as an administrator or programmer you should still avoid these cases wherever possible. You never know when something will be parsed incorrectly, but if one comes your way don't worry about it.

| improve this answer | |
  • Exactly, I wanted to know whether I can keep it as double or single. i.e. double works on the current shell, but am not sure it will work on all the environments. So, it's better to have it single, then. Thanks a lot. – San Apr 25 '11 at 9:33
  • 3
    I suppose the difference is that anything operating on the file system will usually discern the reference to the same folder, but anything doing string matching on your path and not actually parsing it and looking at the disc might see this as different file. For example if you were comparing two files lists, you would want to normalize them by removing duplicate '/'s. If you are passing the string to cd, it won't care. – Caleb Apr 25 '11 at 9:37
  • 3
    I believe POSIX specifies any number of consecutive slashes collapse into one, but I'm uncertain, I do know both Linux and FreeBSD do it in the kernel. It's not the shell that cares. The cases where multiple slashes affects the interpretation are not local filenames. The example caleb gives of a samba path is actually a UNC path and it how Windows (which does not allow multiple slashes) interpret the path. This does not occur normally on UNIX systems as they don't natively support UNC paths. URLs are a different matter and multiple slashes do affect interpretations. – penguin359 Apr 26 '11 at 5:51
  • Why isn't this expanded to include 3 in a row then? If you have $PATH/$OTHERPATH and $PATH = /etc/ and $OTHERPATH = /apt/ then wouldn't this result in "/etc///apt/" ? – Aaron Franke Oct 28 '16 at 4:18
  • it can be corrected by tweaking your path string like path=${path%/} – splaisan Mar 22 '19 at 11:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.