Bash终端命令重命名多个文件 [英] Bash Terminal Command for renaming multiple files

查看:305
本文介绍了Bash终端命令重命名多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所暗示的,我找了一个bash命令(或者甚至一个Perl命令),我可以在终端用它来帮助我的文件夹中重命名文件。

我是一名DJ,并通过包含数百个新的音乐,但文件名的zip文件接收音乐周通常是不一致的,有时文件歌曲的标题前有各种人物。我期待在一个字符串的结尾,以取代第一个字母前的任何字符以及删除任何多余的空格。

 原件< 01  - 艺术家 - 宋.MP3新> ARIST  -  Song.mp3的原始< _Artist  -  Song.mp3的新>艺术家 -  Song.mp3的原始< 04 04)(*)* +艺术家 -  Song.wav新<艺术家 -  Song.wav

我发现了一个正则表达式一个bash几个月前处理字符串中的前[0-9]人物,我已经尝试了一些东西,但没有什么工作,所以我在这里发帖,看看是否有人能帮帮我。任何帮助是极大的AP preciated,先谢谢了!

我尝试

 在F [0-9] *;做
   如果[[$ F =〜^ [0-9] + [:空白:]] +(+)];然后
      NEWNAME =$ {BASH_REMATCH [1]}
      回声> $ NEWNAME
   科幻
DONE


解决方案

如何像

 的sed -r的/(^ [^ A-ZA-Z] * | \\ S +)// G'

每个文件重命名的目录

 的文件中。*;

新的=`回声$文件| SED -r的/(^ [^ A-ZA-Z] * | \\ S +)// g'`;
MV$文件$新;
DONE

As the title suggests, I am looking for a bash command (or maybe even a perl command) that I can use in terminal to help me rename files in a folder.

I am a DJ and receive music weekly via a zip file containing hundreds of new music but file name is usually inconsistent and sometimes files have various characters before the title of the song. I am looking to replace any character before the first letter as well as remove the any extra spaces at the end of a string.

Original < 01 - Artist - Song .mp3

New > Arist - Song.mp3

Original < _Artist - Song.mp3

New > Artist - Song.mp3

Original < 04 04 )(*)*+ Artist - Song.wav

New < Artist - Song.wav

I found a bash with a regex a few months back that handles [0-9] characters in the front of a string and I've tried a few things but nothing really worked so I am posting here to see if someone could help. Any help is greatly appreciated, thanks in advance!

My attempts

for f in [0-9]* ; do
   if[[ $f =~ ^[0-9]+[[:blank:]]+(.+) ]] ; then
      newname = "${BASH_REMATCH[1]}"
      echo "> $newname"
   fi
done

解决方案

How about something like

sed -r 's/(^[^a-zA-Z]*|\s+)//g'

renaming every files in a directory

for file in *;
do 
new=`echo $file | sed -r 's/(^[^a-zA-Z]*|\s+)//g'`; 
mv "$file" $new; 
done

这篇关于Bash终端命令重命名多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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