首页 > /tmp与/tmp/之间的区别?

/tmp与/tmp/之间的区别?

/tmp与/tmp/之间的区别??

使用 cp 目标文件 /tmp/会报错。

但是 cp 目标文件 /tmp 是正确的。


serverfault上的答案
Using commands like cp and mv, use of the trailing slash in the destination acts as a bit of a safety net, since it forces the final path component to be interpreted as a directory. Compare mv myfile /some/path to mv myfile /some/path/ -- if /some/path does not exist, the first version will create a file, while the second version will fail with an error. If /some/path exists but is a file, the first version will replace it, while the second version will again fail with an error.

后面加斜杠,强调是一个目录,/tmp/不存在会报错,如果不加斜杠,命令会给你创建一个/tmp文件。所以为了严谨和安全,总是加上斜杠吧!


/tmp 是一个文件
/tmp/ 是一个目录

【热门文章】
【热门文章】