bash命令从所有文件名中的前导零 [英] Bash command to remove leading zeros from all file names

查看:80
本文介绍了bash命令从所有文件名中的前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆文件的目录与名称类似:

  001234.jpg
001235.jpg
004729342.jpg

我想从所有的文件名称中删除前导零,所以我会留下:

  1234.jpg
1235.jpg
4729342.jpg

我一直在试图sed的不同配置,但我找不到正确的语法。有没有一种简单的方法来列出目录中的所有文件,把它管道sed和移动或将其复制到新的文件名不带前导零?


解决方案

 在`ls`文件;做MV $文件'回声$文件| SED -e的:^ 0 * ::'`; DONE

I have a directory with a bunch of files with names like:

001234.jpg
001235.jpg
004729342.jpg

I want to remove the leading zeros from all file names, so I'd be left with:

1234.jpg
1235.jpg
4729342.jpg

I've been trying different configurations of sed, but I can't find the proper syntax. Is there an easy way to list all files in the directory, pipe it through sed, and either move or copy them to the new file name without the leading zeros?

解决方案

for FILE in `ls`; do mv $FILE `echo $FILE | sed -e 's:^0*::'`; done

这篇关于bash命令从所有文件名中的前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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