ITPub博客

首页 > Linux操作系统 > Linux操作系统 > USING SHELL TO RENAME FILES NAME

USING SHELL TO RENAME FILES NAME

原创 Linux操作系统 作者:xhailiang 时间:2009-05-14 16:44:51 0 删除 编辑

Renaming Files

To rename all files in a directory and add a new extension the xargs command can be used:

ls | xargs -t -i mv {} {}.old

xargs reads each item from the ls ouput and executes the mv command. The ‘-i’ option tells xargs to replace ‘{}’ with the name of each item. The ‘-t’ option instructs xargs to print the command before executing it.

To rename a subset of files, specify the file names with the ls command:

ls *.log | xargs -t -i mv {} {}.old

Or to add a current timestamp extension you may want to use the date command similar to this one:

ls *.log | xargs -t -i mv {} {}.`date +%F-%H:%M:%S`

The extension will look like “.2006-08-10-19:37:16″.

If you want to rename the extension of files, try the rename command:

rename .log .log_archive.`date +%F-%H:%M:%S` *

This command replaces the first occurrence of ‘.log’ in the name by .log_archive.`date +%F-%H:%M:%S`.

The following command replaces .htm extensions with .html for all files that start with “project*”:

rename .htm .html project*

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/308563/viewspace-598163/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-02-17

  • 博文量
    270
  • 访问量
    430100