根据文件名的某些部分将文件移至目录? [英] Move files to directories based on some part of file name?

查看:71
本文介绍了根据文件名的某些部分将文件移至目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数千本名为AuthorFirstName AuthorLastName Title XX.pdf的电子书,其中xx1-99中的数字(卷号).

I have several thousand eBooks named like AuthorFirstName AuthorLastName Title XX.pdf, where xx are number from 1-99 (volume number).

作者倾斜名称可以是多个单词,因此在这里我想将文件复制到名称为AuthorFirstName AuthorLastName title的文件夹中.除数字以外的所有内容都应为文件夹名称,以便该电子书的所有卷都位于同一文件夹中.

Author tilte name can be of multiple word so here i want to move copy the files to folder with the name AuthorFirstName AuthorLastName title. Everything except the number should be the folder name, so that all volumes of the eBook come in same folder.

例如

root.....>AuthorFirstName AuthorLastName Title>AuthorFirstName AuthorLastName Title XX.pdf

推荐答案

我会尝试以下方法:

for folder in $(ls | sed -r "s/(.*) ([0-9]{1,2})/\1/" | uniq)
do 
    mkdir $folder
    mv $(find . -name "$folder*") $folder
done    

我不知道这是否正确,但是可能会给您一些提示.

I don't know if this is correct, but it may give you some hints.

在管道中添加了uniq.

edit: added uniq to the pipe.

这篇关于根据文件名的某些部分将文件移至目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆