Ram*_*ile 3 linux shell awk sed file-rename
我的文件系统中有很多文件,目录和子目录.
例如:
/path/to/file/test-poster.jpg
/anotherpath/my-poster.jpg
/tuxisthebest/ohyes/path/exm/bold-poster.jpg
我想从切换所有文件名*-poster.jpg,以folder.jpg
我与尝试sed并awk没有成功.
一点帮助?
你可以这样做find:
find -name "*poster.jpg" -exec sh -c 'mv "$0" "${0%/*}/folder.jpg"' '{}' \;
Run Code Online (Sandbox Code Playgroud)
在这里,对于匹配的每个文件名,执行:
sh -c 'mv "$0" "${0%/*}/folder.jpg"' '{}'
Run Code Online (Sandbox Code Playgroud)
'{}'文件名在哪里作为参数传递给command_string:
mv "$0" "${0%/*}/folder.jpg"
Run Code Online (Sandbox Code Playgroud)
所以,最后,$0将有文件名.
最后,${0%/*}/folder.jpg扩展到旧文件名的路径并添加/folder.jpg.
请注意我替换mv用echo
$ find -name "*poster.jpg" -exec sh -c 'echo "$0" "${0%/*}/folder.jpg"' '{}' \;
./anotherpath/my-poster.jpg ./anotherpath/folder.jpg
./path/to/file/test-poster.jpg ./path/to/file/folder.jpg
./tuxisthebest/ohyes/path/exm/bold-poster.jpg ./tuxisthebest/ohyes/path/exm/folder.jpg
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
272 次 |
| 最近记录: |