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

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

Will the latter work out? Does the difference have any special meaning for cd, mv, ls, or for any other command, for that matter?


1 Answer 1


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.

  • 1
    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
    Commented Apr 25, 2011 at 9:33
  • 5
    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
    Commented Apr 25, 2011 at 9:37
  • 5
    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
    Commented Apr 26, 2011 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/" ? Commented Oct 28, 2016 at 4:18
  • it can be corrected by tweaking your path string like path=${path%/}
    – splaisan
    Commented Mar 22, 2019 at 11:35

Not the answer you're looking for? Browse other questions tagged .