免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: little_angel
打印 上一主题 下一主题

[文件目录] find调用使用exec和xargs来实现批量文件重命名 [复制链接]

论坛徽章:
5
未羊
日期:2014-08-04 16:15:21天秤座
日期:2014-08-13 13:52:372015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:56:112015亚冠之浦和红钻
日期:2015-06-29 15:30:48
11 [报告]
发表于 2014-10-11 17:00 |只看该作者
rename -V
rename (util-linux-ng 2.17.2)

论坛徽章:
2
2015年亚洲杯之伊拉克
日期:2015-04-13 10:55:1115-16赛季CBA联赛之山西
日期:2016-05-16 09:54:41
12 [报告]
发表于 2014-10-11 17:02 |只看该作者
回复 11# dn833
  1. rename (util-linux-ng 2.17.2)
复制代码

论坛徽章:
5
未羊
日期:2014-08-04 16:15:21天秤座
日期:2014-08-13 13:52:372015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:56:112015亚冠之浦和红钻
日期:2015-06-29 15:30:48
13 [报告]
发表于 2014-10-11 17:03 |只看该作者
那9楼的命令就是ok的

论坛徽章:
3
丑牛
日期:2014-09-13 18:19:22摩羯座
日期:2014-10-10 17:43:02水瓶座
日期:2014-10-16 01:00:22
14 [报告]
发表于 2014-10-12 02:33 |只看该作者
学生党:无聊~包...夜玩耍中~   python试试

  1. #!/usr/bin/env python
  2. #coding:utf-8
  3. "just for fun"

  4. import os
  5. import sys
  6. import shutil

  7. for root, dirs, files in os.walk(sys.argv[1]):
  8.         for f in filter(lambda x:x[-4:]=='.txt',files):
  9.                 shutil.move(f,f[:-4])
复制代码

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
15 [报告]
发表于 2014-10-12 13:39 |只看该作者
回复 9# 关阴月飞

There is the rename utility with perl script and it's safe to rename files after comfirmation

$ ls
a.txt  b.txt  c.txt
   
$ rename -n 's/\.txt$//' *.txt
a.txt renamed as a
b.txt renamed as b
c.txt renamed as c


$ man rename

RENAME(1)              Perl Programmers Reference Guide              RENAME(1)

NAME
       rename - renames multiple files

SYNOPSIS
       rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

DESCRIPTION
       "rename" renames the filenames supplied according to the rule specified
       as the first argument.  The perlexpr argument is a Perl expression
       which is expected to modify the $_ string in Perl for at least some of
       the filenames specified.  If a given filename is not modified by the
       expression, it will not be renamed.  If no filenames are given on the
       command line, filenames will be read via standard input.

       For example, to rename all files matching "*.bak" to strip the
       extension, you might say

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

       To translate uppercase names to lower, you'd use

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

OPTIONS
       -v, --verbose
               Verbose: print names of files successfully renamed.

       -n, --no-act
               No Action: show what files would have been renamed.


       -f, --force
               Force: overwrite existing files.



论坛徽章:
32
处女座
日期:2013-11-20 23:41:20双子座
日期:2014-06-11 17:20:43戌狗
日期:2014-06-16 11:05:00处女座
日期:2014-07-22 17:30:47狮子座
日期:2014-07-28 15:38:17金牛座
日期:2014-08-05 16:34:01亥猪
日期:2014-08-18 13:34:25白羊座
日期:2014-09-02 15:03:55金牛座
日期:2014-11-10 10:23:58处女座
日期:2014-12-02 09:17:52程序设计版块每日发帖之星
日期:2015-06-16 22:20:002015亚冠之塔什干火车头
日期:2015-06-20 23:28:22
16 [报告]
发表于 2014-10-12 13:41 |只看该作者
  1. for file in *.txt;do mv $file ${file%.*};done
复制代码

论坛徽章:
0
17 [报告]
发表于 2014-10-13 08:55 |只看该作者
回复 6# little_angel

是的。


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP