Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I really don't think it matters, commands like 'cd' work either way.
FWIW: using bash, if I use tab to complete a path, it adds the trailing slash. So, if you want to be sure you're operating on a directory, I would add it.
It doesn't matter for most things, as long as it is unambiguous that it is a directory.
It does matter when using rsync however... from man rsync:
Quote:
...A trailing slash on the source changes this behavior to avoid creating an additional directory level at
the destination. You can think of a trailing / on a source as meaning "copy the contents of this direc-
tory" as opposed to "copy the directory by name", but in both cases the attributes of the containing
directory are transferred to the containing directory on the destination.
With bash autocomplete, presence or absence of a tailing slash added by the shell will allow you to visually distinguish between a directory and a symlink to a directory. This behavior can also vary with inputrc directive show-all-if-ambiguous, I think.
It is usually important when used in config files and varies per application.
It doesn't matter for most things, as long as it is unambiguous that it is a directory.
It does matter when using rsync however... from man rsync:
Quote:
...A trailing slash on the source changes this behavior to avoid creating an additional directory level at
the destination. You can think of a trailing / on a source as meaning "copy the contents of this direc-
tory" as opposed to "copy the directory by name", but in both cases the attributes of the containing
directory are transferred to the containing directory on the destination.
If you leave off the trailing slash, it can point to a file or a directory. If you include the trailing slash it can only point to a directory. This can be advantageous in certain cases. For example, say you want to copy A (a file) into B (a directory).
You could use either
Code:
cp A B
or
Code:
cp A B/
If B already exists and is a directory, the two commands are interchangeable, but if B doesn't already exist, or if it does already exist and is a file, the behavior will be quite different.
The former command will just copy the file A to the file B, overwriting its previous contents if necessary.
The latter command will ONLY do anything if B already exists and is a directory. If B doesn't exist or if B is a file, the latter command will throw an error, allowing you to correct the command before accidentally overwriting the file B or creating copies of A where you don't want them.
For that reason, when I'm referring to a directory, I always put a trailing slash on the end so that if I make a mistake in the name it will throw an error rather doing something I don't want it to do.
Last edited by suicidaleggroll; 02-27-2015 at 10:13 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.