bash 创建同名文件和目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33010641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating file and directory with same name
提问by atamit81
In Linux, why can't I create a file and a directory with same name. Seeing following error when test file exists.
在 Linux 中,为什么我不能创建同名的文件和目录。当测试文件存在时看到以下错误。
$mkdir test
mkdir: cannot create directory ‘test': File exists
$cd test
bash: cd: test: Not a directory
回答by Mureinik
A directory is a special kind of a file - one that doesn't have any data of its own, but a list of other files it contains.
目录是一种特殊类型的文件——它没有自己的任何数据,而是它包含的其他文件的列表。
Like with any other file, you can't have two files with the same name in the same location, regardless of whether they are regular files, directories, symbolic links, named pipes, or whatever.
与任何其他文件一样,您不能在同一位置有两个同名文件,无论它们是常规文件、目录、符号链接、命名管道还是其他任何文件。
回答by myaut
You misuse term filewhich is actually can be directory, socket or pipe. The name test
is kept in a directory entry which is linked to inodecorresponding to a file.
您误用了实际上可以是目录、套接字或管道的术语文件。该名称test
保存在目录条目中,该条目链接到对应于文件的inode。
The file in traditional meaning is called regular filein Unix, check S_ISREG
macro in stat(2)call manpage.
传统意义上的文件在 Unix 中称为常规文件,查看stat(2)call manpage 中的S_ISREG
宏。
回答by asvany
If you want, you can create a file and a directory with the same name when you use different capitalization of the letters.
如果需要,可以在使用不同大小写的字母时创建同名的文件和目录。
$mkdir Test ; touch test
$ls -l
-rw-r--r-- 1 user 1002 0 Oct 8 10:52 test
drwxr-xr-x 2 user 1002 40 Oct 8 10:52 Test
$find -iname test
./test
./Test