免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3989 | 回复: 4
打印 上一主题 下一主题

我的rename不支持正则 [复制链接]

论坛徽章:
2
IT运维版块每日发帖之星
日期:2016-02-10 06:20:01IT运维版块每日发帖之星
日期:2016-02-11 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-02-06 23:13 |只看该作者 |倒序浏览
系统是fedora11
rename不支持正则表达式,如何才能让她支持呢?

论坛徽章:
0
2 [报告]
发表于 2010-02-07 05:42 |只看该作者
没用过这个命令~ 是改名吗? 用MV不行吗?

论坛徽章:
2
IT运维版块每日发帖之星
日期:2016-02-10 06:20:01IT运维版块每日发帖之星
日期:2016-02-11 06:20:00
3 [报告]
发表于 2010-02-07 10:38 |只看该作者
是改名的.但是我这个不支持正则,,不知道有什么办法没

论坛徽章:
0
4 [报告]
发表于 2010-02-07 10:55 |只看该作者
cat /usr/bin/rename:

  1. #!/usr/bin/perl -w
  2. #
  3. #  This script was developed by Robin Barker (Robin.Barker@npl.co.uk),
  4. #  from Larry Wall's original script eg/rename from the perl source.
  5. #
  6. #  This script is free software; you can redistribute it and/or modify it
  7. #  under the same terms as Perl itself.
  8. #
  9. # Larry(?)'s RCS header:
  10. #  RCSfile: rename,v   Revision: 4.1   Date: 92/08/07 17:20:30
  11. #
  12. # $RCSfile: rename,v $Revision: 1.5 $Date: 1998/12/18 16:16:31 $
  13. #
  14. # $Log: rename,v $
  15. # Revision 1.5  1998/12/18 16:16:31  rmb1
  16. # moved to perl/source
  17. # changed man documentation to POD
  18. #
  19. # Revision 1.4  1997/02/27  17:19:26  rmb1
  20. # corrected usage string
  21. #
  22. # Revision 1.3  1997/02/27  16:39:07  rmb1
  23. # added -v
  24. #
  25. # Revision 1.2  1997/02/27  16:15:40  rmb1
  26. # *** empty log message ***
  27. #
  28. # Revision 1.1  1997/02/27  15:48:51  rmb1
  29. # Initial revision
  30. #

  31. use strict;

  32. use Getopt::Long;
  33. Getopt::Long::Configure('bundling');

  34. my ($verbose, $no_act, $force, $op);

  35. die "Usage: rename [-v] [-n] [-f] perlexpr [filenames]\n"
  36.     unless GetOptions(
  37.         'v|verbose' => \$verbose,
  38.         'n|no-act'  => \$no_act,
  39.         'f|force'   => \$force,
  40.     ) and $op = shift;

  41. $verbose++ if $no_act;

  42. if (!@ARGV) {
  43.     print "reading filenames from STDIN\n" if $verbose;
  44.     @ARGV = <STDIN>;
  45.     chop(@ARGV);
  46. }

  47. for (@ARGV) {
  48.     my $was = $_;
  49.     eval $op;
  50.     die $@ if $@;
  51.     next if $was eq $_; # ignore quietly
  52.     if (-e $_ and !$force)
  53.     {
  54.         warn  "$was not renamed: $_ already exists\n";
  55.     }
  56.     elsif ($no_act or rename $was, $_)
  57.     {
  58.         print "$was renamed as $_\n" if $verbose;
  59.     }
  60.     else
  61.     {
  62.         warn  "Can't rename $was $_: $!\n";
  63.     }
  64. }

  65. __END__

  66. =head1 NAME

  67. rename - renames multiple files

  68. =head1 SYNOPSIS

  69. B<rename> S<[ B<-v> ]> S<[ B<-n> ]> S<[ B<-f> ]> I<perlexpr> S<[ I<files> ]>

  70. =head1 DESCRIPTION

  71. C<rename>
  72. renames the filenames supplied according to the rule specified as the
  73. first argument.
  74. The I<perlexpr>
  75. argument is a Perl expression which is expected to modify the C<$_>
  76. string in Perl for at least some of the filenames specified.
  77. If a given filename is not modified by the expression, it will not be
  78. renamed.
  79. If no filenames are given on the command line, filenames will be read
  80. via standard input.

  81. For example, to rename all files matching C<*.bak> to strip the extension,
  82. you might say

  83.         rename 's/\.bak$//' *.bak

  84. To translate uppercase names to lower, you'd use

  85.         rename 'y/A-Z/a-z/' *

  86. =head1 OPTIONS

  87. =over 8

  88. =item B<-v>, B<--verbose>

  89. Verbose: print names of files successfully renamed.

  90. =item B<-n>, B<--no-act>

  91. No Action: show what files would have been renamed.

  92. =item B<-f>, B<--force>

  93. Force: overwrite existing files.

  94. =back

  95. =head1 ENVIRONMENT

  96. No environment variables are used.

  97. =head1 AUTHOR

  98. Larry Wall

  99. =head1 SEE ALSO

  100. mv(1), perl(1)

  101. =head1 DIAGNOSTICS

  102. If you give an invalid Perl expression you'll get a syntax error.

  103. =head1 BUGS

  104. The original C<rename> did not check for the existence of target filenames,
  105. so had to be used with care.  I hope I've fixed that (Robin Barker).

  106. =cut

复制代码

论坛徽章:
1
巨蟹座
日期:2014-06-04 13:33:30
5 [报告]
发表于 2010-02-08 11:57 |只看该作者
我的centos是原始的rename
debian就不是了
把4楼的代码保存成prenmae,再运行它就可以了(系统要有perl)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP