我用这一行删除文件夹名称上的空格
find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;
Run Code Online (Sandbox Code Playgroud)
有没有办法从文件名中删除空格和括号并添加下划线?
例如,我有:
|-- 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
Run Code Online (Sandbox Code Playgroud)
必须成为
|-- 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
Run Code Online (Sandbox Code Playgroud)
您可以使用:
find /tmp/ -depth -name "*[ ()]*" -execdir rename 's/[ )]/_/g; s/\(//g' "{}" \;
Run Code Online (Sandbox Code Playgroud)