击:移动多个文件到子文件夹 [英] Bash: Moving multiple files into subfolders
本文介绍了击:移动多个文件到子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一对夫妇一千文件的文件夹,我想根据文件名字符串将其移动到子文件夹。这些文件均具有类似的结构。
东西-run1_001.txt
东西-run22_1243.txt
所以,我想下面的脚本,以便在它移动所有文件RUN1到子文件夹r1和子文件夹R22所有的run22文件(等等),但它确实没有工作的方式,我得到消息文件X是相同文件X。
#!斌/庆典因为我在{} 1..39
做
FOLDERNAME = R $ I
#echo$文件夹名
MKDIR $ FOLDERNAME
找 。型的F -name*运行$ I_ *| xargs的-i MV {} $文件夹名/
DONE
如何解决此问题?
解决方案
为我在{} 1..39
做
MKDIR -p R $ {I} /
MV *运行$ {I} _ * R $ {I} /
DONE
I have a folder with a couple thousand files and I want to move them into subfolders according to a string in the filename. The files all have a structure like
something-run1_001.txt
something-run22_1243.txt
So I tried the following script in order to move all files with "run1" in it into a subfolder r1 and all "run22" files in a subfolder r22 (and so on) but it does no work that way and I get a message "File X is the same as file X".
#!bin/bash
for i in {1..39}
do
foldername=r$i
#echo "$foldername"
mkdir $foldername
find . -type f -name "*run$i_*" | xargs -i mv {} $foldername/
done
How to solve this?
解决方案
for i in {1..39}
do
mkdir -p r${i}/
mv *run${i}_* r${i}/
done
这篇关于击:移动多个文件到子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文