I am a CentOS user for many years now, but I am still often not sure how the final slash matters in linux commands, e.g.
- tar
- rsync
- mv
- file handling in software/php
What is the actual difference between paths ending and not ending with a slash?
feedback
|
|
The answer is "it depends". Many commands don't care, though this changes if the filename given is a symlink to a directory. With a trailing slash, most commands will use the directory the symlink points to, without a trailing slash the command will use the symlink itself. Some commands like | |||||
feedback
|
|
the truth is that it generally depends on the command running for example rsync with the slash specifically starts at the contents of that directory whereas without the slash it will start at that directory, then its contents. for all intents and purposes for most commands it wont matter but if your not sure you consult the manual for each command eg
| |||
|
feedback
|
|
I'm not 100% sure, how the trailing slash affects cp, mv, rm, though it my experience it doesn't have any practical effect. e.g. running cp -r dir1 dir2 will give you the same result as cp -r dir1/ dir2 It definitely matters for rsync. In rsync the difference between including and omitting the trailing slash is the difference between syncing the contents of the directory or the directory itself and the contents. e.g. rsync -a dir1 dir2 will create a dir1 under dir2 while rsync -a dir1/ dir2 will create copies of any files in dir1 directly in dir2 | |||
|
feedback
|
|
It really depends on the program. For instance, find will follow the symlink on a path with a trailaing slash.
will return nothing
will find "dir2/" and continue to recurse through dir1. | |||
|
feedback
|