

//foo是个什么目录?
source link: https://www.lujun9972.win/blog/2019/09/16/-foo%E6%98%AF%E4%B8%AA%E4%BB%80%E4%B9%88%E7%9B%AE%E5%BD%95-/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

//foo是个什么目录?
从 https://jvns.ca/blog/2017/02/08/weird-unix-things-cd/ 上看到的,觉得很神奇,记录一下
在bash下执行下面命令看看结果是什么
cd /tmp pwd cd //tmp pwd cd ///tmp pwd cd ////tmp pwd
/tmp //tmp /tmp /tmp
貌似中间混入了一个奇怪的东西 //tmp
, 这是什么玩意?? 我们来看看它的inode
stat //tmp
文件://tmp 大小:740 块:0 IO 块:4096 目录 设备:2dh/45d Inode:12972 硬链接:17 权限:(1777/drwxrwxrwt) Uid:( 0/ root) Gid:( 0/ root) 最近访问:2019-09-16 21:52:50.368212128 +0800 最近更改:2019-09-16 22:29:22.768083948 +0800 最近改动:2019-09-16 22:29:22.768083948 +0800 创建时间:-
可以看到inode为12972,那么这个inode其实应该属于哪个文件呢?
find / -inum 12972;:
/tmp
你会发现 //tmp
其实就是 /tmp
怎么会这样呢?
根据 cd
的规范
An implementation may further simplify curpath by removing any trailing <slash> characters that are not also leading <slash> characters, replacing multiple non-leading consecutive <slash> characters with a single <slash>, and replacing three or more leading <slash> characters with a single <slash>. If, as a result of this canonicalization, the curpath variable is null, no further steps shall be taken.
总结起来就是几点:
- 路径最后的"/"可以被省略,即
/foo//
可以简化成/foo
- 非首部的多个连续""可以被简化成一个"",即
/foo//bar
可以简化成/foo/bar
- 首部的三个或以上连续的""可以被简化成一个"",即
///foo
可以简化成/foo
- 首部是两个连续的"/"的情况没有定义,也就是可以有不同的实现方式
Recommend
-
121
最近ICO很火,带来了非常多人关注这块。很多人都会问,区块链到底是什么?但说到区块链,网上各种各样的资料满天飞,看完之后,感觉懂了,又感觉完全没懂。 一句话概括,如果互联网技术解决的是通讯问题的话,区块链技术解决的是信任问题。 妈:“小明啊,什么是区...
-
85
熟悉 Vue 的同学们都知道,Vue 有个 nextTick 方法,用来异步更新数据。 来看看这个栗子: <body> <div id="main"> <ul class="list">
-
37
问与答 - @yidinghe - 以软考里面最基础的 [程序员考试]( http://www.ruankao.org.cn/platform/details?code=01_18) 来说:1. 这个资质在行业当中有用吗?1
-
13
Escape your literary echo chamber! 📚Break the Bubble allows you to find out which books you are statistically unlikely to read. The more narrow your reading tastes are, the more you will be challenged by the...
-
11
Private brand checks a.k.a. #foo in objPublished 14 April 2021 · Tagged with ECMAScriptThe
-
13
'date -d' vs. 'date -s', and 'show foo' vs. 'clear foo' Here's something fun I saw which created an outage once. I've written about this before, but in light of yesterday...
-
6
Issues · ICTman1076/foo_maloja · GitHub Clear current search query, filters, and sorts Author Label...
-
9
Article c++ `struct Foo f;` and `struct Foo f{};` are very different Lu Pan 01 Nov 2021 • 2 min read
-
8
Master Foo and the Recruiter Master Foo and the RecruiterA technical recruiter, having discovered th...
-
6
Closed Bug 1552055...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK