如何重命名文件夹中的所有文件,删除Linux中空格字符后的所有内容? [英] How to rename all files in a folder removing everything after space character in linux?

查看:248
本文介绍了如何重命名文件夹中的所有文件,删除Linux中空格字符后的所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我整天在Internet上搜索时都不能很好地使用正则表达式. 我的文件夹里有很多照片:

Hello I can't use well the regular expressions it's all day I'm searching on Internet. I have a folder with many pictures:

  • 50912000 Bicchiere.jpg
  • 50913714 Sottobottiglia Bernini.jpg

我使用的是Mac OS X,但我也可以尝试在Ubuntu上使用,我想为bash编写一个脚本,以删除第一个空格后的所有字符,以实现以下解决方案:

I'm using Mac OS X, but I can also try on a Ubuntu, I would like to make a script for bash to remove all the characters after the first space to have a solution like this:

  • 50912000.jpg
  • 50913714.jpg

对于文件夹中的所有文件. 任何帮助表示赞赏. 问候

For all the files in the folder. Any help is appreciated. Regards

推荐答案

使用纯BASH:

f='50912000 Bicchiere.jpg'
mv "$f" "${f/ *./.}"

或使用find一次修复所有文件:

Or using find fix all the files at once:

find . -type f -name "* *" -exec bash -c 'f="$1"; s="${f/_ / }"; mv -- "$f" "${s/ *./.}"' _ '{}' \;

这篇关于如何重命名文件夹中的所有文件,删除Linux中空格字符后的所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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