在Linux中从文件名中删除空格 [英] Remove whitespaces from filenames in Linux

查看:1063
本文介绍了在Linux中从文件名中删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在不同的文件夹中有数百个jpg文件,如下所示:

I have hundreds of jpg files in different folders like this:

  • 304775 105_01.jpg
  • 304775 105_03.jpg
  • 304775 105_05.jpg
  • 304775 105_07.jpg
  • 304775 105_02.jpg
  • 304775 105_04.jpg
  • 304775 105_06.jpg

基本上,我需要删除空间.我已经知道将空格更改为下划线的命令:

Basically, I need to remove the SPACES. I already know the command to change the spaces into underscores:

$ rename "s/ /_/g" *

但是在这种情况下,我不需要下划线.我只需要删除空间.我尝试了以下操作,但没有成功:

But I do not need the underscores in this case. I just need to remove the space. I tried the following, but it didn't work:

$ rename "s/ //g" *

任何帮助将不胜感激.

推荐答案

您可以执行以下操作:

IFS="\n"
for file in *.jpg;
do
    mv "$file" "${file//[[:space:]]}"
done

这篇关于在Linux中从文件名中删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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