What is difference between dir and dir/ in linux terminal or in dos?
For Example : In any command when we need to refer any directory. Then we use dirname
or dirname/
what is the difference between them?
For e.g. cd dirname
vs cd dirname/
and cp -R dirname1 dirname2
vs cp -R dirname1 dirname2/
vs c开发者_如何学Gop -R dirname1/ dirname2/
dirname
is the directory. dirname\
is a path whose last node is the directory.
In most contexts you can get away with using either, but that's not always the case.
Usually if you're trying to, say, copy a file into a directory, cp file dirname\
to make clear that you're copying it to a new path. Visualise file
being appended to the path, to become dirname\file
. This is most important when working with symbolic links, as the file system isn't quite as clever at auto-translating dirname
to dirname\
as required, when dirname
is a symlink.
For linux shell: In general, either one will work. Assuming the two filenames actually are directories, including or omitting the final slash should be optional.
Cases where you might notice a difference:
- if dirname is actually a symbolic link to a directory, using the final / will fail
- a few commands, like rsync, specifically treat filename arguments ending with / differently
At least in a DOS/Windows shell, there usually is no difference. There is one exception I know:
If you use
xcopy somefile C:\somepath
and somepath
doesn't exist, xcopy asks if somepath
is a file or a directory to be created, which can be avoided using
xcopy somefile C:\somepath\
which will just create somepath
and copy somefile
in there.
So in that case, somepath\
makes it clearer that it's a path. Anyway, usually you're referring to a path that already exists, so there'll be no difference between the two cases.
精彩评论