文件类型, 路径问题
Linux 下的文件类型 一切皆文件 everything is file
我对一切皆文件的理解, linux 下不存在具体的文件类型或后缀名. exe .db .config, 这种后缀可以理解为人为的为了分别文件的类型而设置的, 而在 linux 中系统不考虑文件类型, 会直接运行.
举个例子, 我们在 / app 下创建一个内容为 echo 'hello world' 的 hello.txt 文件然后按照 windows 下的扩展名更改扩展名
看看会发生什么
- [root@localhost app]# echo "echo hello world">hello.txt
- [root@localhost app]# ls
- hello.txt
- [root@localhost app]# cat hello.txt
- echo hello world
- [root@localhost app]# chmod 777 hello.txt
- [root@localhost app]# ./hello.txt
- hello world
我们尝试将 txt 格式转换为. sh 然后运行发现结果一样可能是巧合
- [root@localhost app]# mv hello.txt hello.sh
- [root@localhost app]# ./hello.sh
- hello world
我们再尝试将. sh 格式转换为. mp3 然后运行发现结果一样
这次因为我们都知道 MP3 是音乐媒体格式按照 windows 的逻辑肯定会报错
但在 linux 下运行没有报错或显示内容
- [root@localhost app]# mv hello.sh hello.mp3
- [root@localhost app]# ./hello.mp3
- hello world
同样的将 MP3 转换 png 也是一样的
- [root@localhost app]# mv hello.mp3 hello.png
- [root@localhost app]# ./hello.png
- hello world
我们用大胆的想法去删除它的扩展名
结果发现还是正常的运行了
- [root@localhost app]# mv hello.png hello
- [root@localhost app]# ./hello
- hello world
最后我用打错了的方式随意起名
发现也没有任何影响
- [root@localhost app]# mv hello hel.fdshfujahjk213sda.sad
- [root@localhost app]# ./hel.fdshfujahjk213sda.sad
- hello world
我们可以得出结论, linux 下不存在扩展名, 只存在文件名, 所谓的扩展名只是
人们为了区分文件而自行加上的字符
? -: 普通文件 *
? d: 目录文件 *
? b: 块设备
? c: 字符设备
? l: 符号链接文件 *
? p: 管道文件 pipe
? s: 套接字文件 sock
路径问题
绝对路径: 从根出发一直到目标
相对路径: 相对父目录
. 为当前路径
.. 为上级路径即父路径
来源: http://www.bubuko.com/infodetail-2685305.html