int*_*tar 3 linux bash rename bulk-action
我有一堆(价值约 10 场)文件,需要从外部 linux 磁盘复制到 Windows 机器。不幸的是,一些包含“:”字符的文件名进入了这个集合。
这些冒号文件都不需要在 Windows 机器上,所以我需要一个快速的解决方案来改变或重命名它们。
大家会推荐什么?(我假设类似于 Linux 中的 bash/perl/python 脚本。我们在 Windows 机器上没有 powershell。)
Dan*_*ley 16
查看有问题的文件。
find /path/to/files -name '*:*' -print
Run Code Online (Sandbox Code Playgroud)
删除有问题的文件。
find /path/to/files -name '*:*' -exec rm {} +
Run Code Online (Sandbox Code Playgroud)
用下划线重命名有问题的文件。
find /path/to/files -name '*:*' -exec rename ':' '_' {} +
Run Code Online (Sandbox Code Playgroud)
要获得更高效的 Dan C 版本,请删除一些 UNIX 变体支持:
find /path/to/files -name '*:*' -delete
Run Code Online (Sandbox Code Playgroud)
这避免了/bin/rm对每个匹配文件进行 fork 和 exec 的需要。
此-delete选项存在于 MacOS X 和我的 FC11 系统(带有findutils-4.4.0)。我不知道它是多久前添加到findutils.
| 归档时间: |
|
| 查看次数: |
3117 次 |
| 最近记录: |