我有一个文件夹 A,里面包含文件夹 B,文件夹 B 里面有很多文件。我想删除文件夹 B,但不删除其内容。我希望这些内容位于文件夹 A 内。如何在命令行上实现此操作?
答案1
$ cd /path/to/folderA
$ mv folderB/* .
$ rmdir folderB
答案2
快速回答:
cd /path/to/folderA
find folderB -maxdepth 1 -mindepth 1 -exec mv {} . \;
rmdir folderB
代码难懂的答案:
cd /path/to/folderA
folderB_temp="$(mktemp -d -t folderB.XXXXXX)"
mv folderB "$folderB_temp"
find "$folderB_temp/folderB" -maxdepth 1 -mindepth 1 -exec mv {} . \;
rmdir --parents --ignore-fail-on-non-empty "$folderB_temp/folderB"