批量修改文件名

3 views
Skip to first unread message

yc.hahn

unread,
Feb 4, 2009, 4:11:11 AM2/4/09
to xiyou...@googlegroups.com
系统中大量文件以时间顺序命名,如2008_1_20_13:21.tar.gz, 现在要把这些文件拷贝到Windows下,
可这种中间带"  :"的文件名在Windows下不支持,拷不过去。
请教一下如何写一个bash脚本循环去掉中间的" :"?

vvoody

unread,
Feb 4, 2009, 5:46:54 AM2/4/09
to yc.hahn, xiyou...@googlegroups.com
2009/2/4 yc.hahn <youngch...@gmail.com>:

> 系统中大量文件以时间顺序命名,如2008_1_20_13:21.tar.gz, 现在要把这些文件拷贝到Windows下,
> 可这种中间带" :"的文件名在Windows下不支持,拷不过去。
> 请教一下如何写一个bash脚本循环去掉中间的" :"?
>

$ for f in *.tar.gz; do newf=$(echo $f | tr -d ':'); mv $f $newf; done

--
Free as freedom, slack as Slackware.
vvoody

李磊

unread,
Feb 4, 2009, 5:50:56 AM2/4/09
to yc.hahn, xiyou...@googlegroups.com
2009/2/4 yc.hahn <youngch...@gmail.com>:

> 系统中大量文件以时间顺序命名,如2008_1_20_13:21.tar.gz, 现在要把这些文件拷贝到Windows下,
> 可这种中间带" :"的文件名在Windows下不支持,拷不过去。
> 请教一下如何写一个bash脚本循环去掉中间的" :"?
http://groups.google.com/group/xiyoulinux/browse_thread/thread/88b46cf23ee2b19d/b9870cc7a9e2d05a?hl=zh-CN&lnk=gst&q=%E4%B8%A4%E4%B8%AA%E5%AE%9E%E7%94%A8%E7%9A%84+shell+%E5%B0%8F%E7%A8%8B%E5%BA%8F#b9870cc7a9e2d05a

参考下这里,如果还有疑问再提出。
>
> >
>

yc.hahn

unread,
Feb 4, 2009, 7:18:00 AM2/4/09
to vvoody, xiyou...@googlegroups.com
谢谢了,按照vvoody兄的在Linux PC机上试过成功了,明天再QNX里试一下!
多谢!!!
Reply all
Reply to author
Forward
0 new messages