【发布时间】:2022-06-11 22:08:43
【问题描述】:
我在共享文件夹中有 > 400.000 个文件
mol0.pdb
mol1.pdb
mol2.pdb
...
mol999.pdb
...
mol422222.pdb
我需要将所有这些曲目分成 4 个相等的部分(按文件的数量,假设最后一部分可能比其余部分小一点)并为每个部分创建单独的文件夹(与初始文件夹添加 part_N 后缀)并将每个部分复制到其中。为此,我正在尝试实现简单的 bash 工作流程:
#!/bin/bash
home="$PWD"
project='ALL_pdb' # name of the folder with all pdb filles
#############
input="${home}"/"${project}"
output="${home}"/"${project}"_parts # name of the folder with devided files
# format of the inputs
format='pdb'
# 1- devide all filles in the input to the 4 equal parts
# 2- then iterative over the all filles and copy it to the subfolder
for lig in ${input}/*.${format}; do
lig_name=$(basename "$lig" .${format})
# mkdir $output_part_$i
# cp lig $output_part_$i
# etc
done
如何将填充物的设计自动化并将其进一步转移到单个文件夹会更好?
【问题讨论】:
-
你所说的“相等”部分是什么意思?文件的数量(这是不可能的,因为 422222 不能被 4 整除)?已用磁盘空间? ...?
-
完全按照填充的数量!好吧,最后一部分可能会比其余部分小:-)
-
你介意最后一部分比其余部分大吗?
-
正常情况下,代码应该与位于同一文件夹中的任意数量的输入文件一起工作,并尝试将它们分成几个相等的部分。我认为最好尊重文件 ID,因此将 mol0-mol100000 放在第一个文件夹中,将 mol100000-mol200000 放在第二个文件夹中等等。在脚本的开头定义所需段的数量(单独部分)
标签: bash