请求 linux 命令将一些分散的文件放在一起

Asking for a linux command to put some scattered files together

在我的 Mac OS 文件系统中,我将一些文件组织成 Root_Folder 如下所示:

Root_Folder/
      /Sub_Folder1
              file1
      /Sub_Folder2
              file2
       ....
      /Sub_FolderN
              fileN

现在我想把所有这些 file1...fileN 放到另一个文件夹中,没有那些 Sub_Folders。是否有一个神奇的 linux 命令可以实现这一点?

请注意,sub_folders 的真实姓名彼此相差很大,因此使用 "cp Root_Folder/Sub_Folder*/* Another_Folder" 应该行不通。此外,file_i 的真实姓名上面也各不相同,所以复制到同一个地方的时候不用担心名字冲突。

下面的命令应该可以解决问题:

cp Root_Folder/*/* Another_Folder

但是,您需要确保文件名是唯一的,否则 Sub_Folder2 中的 file1 会覆盖 Sub_Folder1 中的 file1

使用find实用程序:

find Root_Folder -type f -exec mv {} Another_Folder \;

找到所有文件(不是目录)并执行命令:

mv $CURRENT_FILE Another_Folder
find RootFolder -type f -print | xargs -I file echo mv file newdir/

将找到RootFolder下的所有文件并将它们移动到newdir中。如果要保留原始文件,请将 mv 替换为 cp