Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.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
Linux 将子文件夹重命名为parentfolder,删除';额外';文件夹_Linux_Macos_Bash_Shell_Rsync - Fatal编程技术网

Linux 将子文件夹重命名为parentfolder,删除';额外';文件夹

Linux 将子文件夹重命名为parentfolder,删除';额外';文件夹,linux,macos,bash,shell,rsync,Linux,Macos,Bash,Shell,Rsync,当我把rsync搞砸了,忘了添加一个尾随斜杠时,我遇到了这个问题 现在我有了一个额外的文件夹 当前折叠树 /Volumes/hd/images1/images1/ /Volumes/hd/images2/images2/ /Volumes/hd/images3/images3/ 我想得到这个 /Volumes/hd/images1/ /Volumes/hd/images2/ /Volumes/hd/images3/ 有没有办法摆脱多余的文件夹,以得到我想要的,我试图 mv /Volumes/

当我把rsync搞砸了,忘了添加一个尾随斜杠时,我遇到了这个问题

现在我有了一个额外的文件夹

当前折叠树

/Volumes/hd/images1/images1/
/Volumes/hd/images2/images2/
/Volumes/hd/images3/images3/
我想得到这个

/Volumes/hd/images1/
/Volumes/hd/images2/
/Volumes/hd/images3/
有没有办法摆脱多余的文件夹,以得到我想要的,我试图

mv /Volumes/hd/images1/images1/ /Volumes/hd/images1/
但是有一个错误,说它们是相同的,我也尝试了一些基本的php脚本为我做的工作,没有任何运气

我不能删除或真正复制文件夹的内容,因为它有大量的数据,我可以手动更改父文件夹的名称,然后将子文件夹拖动到/hd,然后删除旧的父文件夹。但这是一项艰巨的工作,所以如果有人知道如何做,我会非常高兴


如果您对Mac OS X感兴趣,我会使用它。

您应该学习如何使用shell命令,可能类似于

 for f in /volumes/hd/* ; do
    b=$(basename $f)
    d=$(dirname $f)
    mv $f $d/$b.dir
    mv $d/$b.dir/* $f
 done
首先用
echo mv


您真的应该学习如何在MacOSX上使用基本的Unix命令(在终端内部)

我认为您的最后一个想法是:

更改父文件夹的名称,然后将子文件夹拖动到/hd,然后删除旧的父文件夹

但不要手动操作。您可以编写一个shell脚本来完成这项工作。伪代码:

for parent in `ls /Volumes/hd/` do
  exec 'mv ' + parent + ' ' + parent + '.old'
  exec 'mv ' + parent + '.old/' + parent + ' ' + '/Volumes/hd/'
  exec 'rmdir ' + parent + '.old
end

谢谢你,我知道,它在我的待办事项清单上。我试试这个!