从终端批量替换文件名中的字符吗? [英] Mass replace characters in filenames from terminal?

查看:184
本文介绍了从终端批量替换文件名中的字符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目录中大约有50个文件,其中包含空格,撇号等.如何对它们进行批量重命名以删除撇号并用下划线替换空格?

I have about 50 files in a directory that contain spaces, apostrophes, etc. How can I go about mass-renaming them to remove the apostrophes and replaces spaces with underscores?

我可以做到

ls | grep '*.txt' | xargs ....

但是我不确定在xargs位中做什么

but I'm not sure what to do in the xargs bit

推荐答案

我使用 ren-regexp ,这是一个Perl脚本,可让您非常轻松地批量重命名文件.

I use ren-regexp, which is a Perl script that lets you mass-rename files very easily.

您将执行类似ren-regexp 's/ /_/g' *.txt的操作.

$ ls -l
total 16
-rw-r--r--  1 marc  marc  7 Apr 11 21:18 That's a wrap.txt
-rw-r--r--  1 marc  marc  6 Apr 11 21:18 What's the time.txt

$ ren-regexp "s/\'//g" "s/ /_/g" *.txt

  That's a wrap.txt
1 Thats a wrap.txt
2 Thats_a_wrap.txt

  What's the time.txt
1 Whats the time.txt
2 Whats_the_time.txt


$ ls -l
total 16
-rw-r--r--  1 marc  marc  7 Apr 11 21:18 Thats_a_wrap.txt
-rw-r--r--  1 marc  marc  6 Apr 11 21:18 Whats_the_time.txt

这篇关于从终端批量替换文件名中的字符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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