用下划线替换文件名中的括号和空格 [英] Replace parentheses and spaces in filenames with underscore

查看:95
本文介绍了用下划线替换文件名中的括号和空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此行删除文件夹名称上的空白

I use this line to remove blank spaces on folder name

find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;

是否可以从文件名中删除空格和括号,并在其下划线?

Is there a way to remove SPACES and PARENTHESES from filename and put underscore?

例如,我有:

|-- a_dir
|   `-- (1) file with spaces and parentheses.pdf
`-- b_dir
    |-- (43) another file with spaces (1).pdf
    `-- (132) yet another file with spaces (3343).pdf

必须成为

|-- a_dir
|   `-- 1_file_with_spaces_and_parentheses.pdf
`-- b_dir
    |-- 43_another_file_with_spaces_1.pdf
    `-- 132_yet_another_file_with_spaces_3343.pdf

推荐答案

您可以使用:

find /tmp/ -depth -name "*[ ()]*" -execdir rename 's/[ )]/_/g; s/\(//g' "{}" \;

这篇关于用下划线替换文件名中的括号和空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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