Is there any difference between a directory name such asmydirectoryandmydirectory/I noticed this happens when I execute ls in some directories - some of the directory names have a slash and some don't. This is problematic because if I want to access a file contained in a directory, I may need to add a slash at the end:vi $mydirectory/$myfileor simply do vi $mydirectory$myfile
What is the difference between a directory name that ends with a slash and one that does not?
files;filenames;slash
Without / it might also be a file.In some situations it can be deadly. For example when using mv:mv file1 mydirectorymv file2 mydirectorymv file3 mydirectoryAll right? But if mydirectory did not exist or wasn't a directory, the final result is that file1 and file2 are gone and file3 is now named mydirectory.mv file1 mydirectory/mv file2 mydirectory/mv file3 mydirectory/If mydirectory did not exist, all you get is three error messages and file1, file2 and file3 are still there.So the / removes some ambiguity.Apart from that there aren't really any rules. Some programs may behave differently depending whether you supplied the / at the end or not. It's up to them what to make of it.In some cases you also get problems if you use too many /. For example find keeps surplus / in its output, which might trip you up if you try to find file/pathnames using simple string comparisons instead of, say, realpath or something.