linux - /tmp与/tmp/之间的区别?
PHP中文网
PHP中文网 2017-04-17 13:35:48
[Linux讨论组]

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

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

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

PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(2)
伊谢尔伦

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/ 是一个目录

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号