Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 在UNIX中将文件和目录移动到子文件夹_Shell_Unix_Mv - Fatal编程技术网

Shell 在UNIX中将文件和目录移动到子文件夹

Shell 在UNIX中将文件和目录移动到子文件夹,shell,unix,mv,Shell,Unix,Mv,我打字的时候 mv ../* . mv: cannot move '../<dir name>' to a subdirectory of itself, './<dir name>' mv../*。 mv:无法将“../”移动到其自身的子目录“../” shell/mv命令是如何检测这种行为的?据我所知,mv使用POSIX系统调用,规范中规定: 如果出现以下情况,rename()函数将失败: (……) [EINVAL][CX]新目录 路径名包含一个路径前缀 命名旧

我打字的时候

mv ../* . 
mv: cannot move '../<dir name>' to a subdirectory of itself, './<dir name>'
mv../*。
mv:无法将“../”移动到其自身的子目录“../”

shell/mv命令是如何检测这种行为的?

据我所知,mv使用POSIX系统调用,规范中规定:

如果出现以下情况,rename()函数将失败:

(……)

[EINVAL][CX]新目录 路径名包含一个路径前缀 命名旧目录

。。。以及无数其他详细的故障模式


操作系统可能通过比较层次结构中中间目录的索引节点号来在通用VFS层实现检测。

在将命令行传递给
mv
之前,shell负责扩展通配符,如
*
,并直接执行此操作,仅基于存在的文件/目录,不知道程序是什么,也不知道它可能要对这些名称执行什么操作。因此,在本例中,
。/*
扩展到父目录中的每个文件/目录名,包括当前目录。然后,
mv
遍历它接收到的参数列表,试图将除最后一个之外的所有参数移到最后一个,这会导致您看到的错误。

那么,它怎么知道最后一个条目就是它自己呢?mv是否检查它是否试图自行移动`