批量重命名文件名
来源:互联网 发布:linux ftp和vsftp 编辑:程序博客网 时间:2024/05/17 01:27
批量重命名文件名是常见的需求。例如我们这有三个文件都是以.txt结尾,现在我们想重命名为.csv文件。以下给同学们介绍如下两种方式。
1.使用mv命令
话不多少,直接上代码
#!/bin/bashfor file in `ls`do newfile=`echo $file | sed 's/\.txt/\.csv/'` mv $file $newfiledone
mv的方式如上。如果不是修改后缀而是其他方式,修改后面sed的正则表达方式即可。
2.使用rename命令
rename .txt .csv *
rename 命令可能实际中用得不如mv多。rename最大的好处就是可以同时处理多个文件。来看看rename的用法:
RENAME(1) Linux Programmer’s Manual RENAME(1)NAME rename - Rename filesSYNOPSIS rename from to file... rename -VDESCRIPTION rename will rename the specified files by replacing the first occurrence of from in their name by to. -V, --version Display version information and exit. For example, given the files foo1, ..., foo9, foo10, ..., foo278, the commands rename foo foo0 foo? rename foo foo0 foo?? will turn them into foo001, ..., foo009, foo010, ..., foo278. And rename .htm .html *.htm will fix the extension of your html files.SEE ALSO mmv(1), mv(1)AVAILABILITY The rename command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/. 1 January 2000 RENAME(1)
需要注意的是,rename使用时需要有三个参数。而且注意一下rename的通配符:
? 可替代单个字符* 可替代多个字符* [charset] 可替代charset集中的任意单个字符
0 0
- linux -- 批量重命名文件名
- 批量重命名文件名
- 批量重命名文件名
- matlab批量重命名文件名
- 批量修改文件名 批量重命名
- 文件名批量重命名、文件后缀名批量重命名
- Centos 7 批量重命名文件名
- 一个批量重命名文件名的shell脚本
- linux 批量 含空格文件名 重命名
- shell 文件名分割,重命名移动批量文件
- 当前目录下批量文件名重命名
- 批量重命名,提取文件名、文件后缀名
- linux批量重命名多个目录下文件名
- Python 批量给文件重命名,添加文件名后缀
- 如何批量实现通过MP3标题重命名文件名
- 批量重命名
- 批量重命名
- 批量重命名
- 快速排序Sort调用
- 一个好用的Tag函数
- python3的虚拟环境
- 基础的 Linux 网络命令,你值得拥有
- 99. Recover Binary Search Tree
- 批量重命名文件名
- json、gson、fastjson的简单用法
- Android绘制闹钟效果
- Spring【一】
- Leetcode-73. Set Matrix Zeroes
- 先验概率、后验概率、贝叶斯公式、 似然函数
- 实现微信中的聊天界面Demo
- 数据结构实验之链表四:有序链表的归并
- Git中的分支(branch)概述