问题描述
我创建了一个文件列表,这些文件的名称使用大写字母,并尝试将它们重命名为具有相同名称但使用小写字母的文件。因此,如果我有20个文件名分别为FILE1,FILE2,FILE3等的文件,我想将它们分别重命名为file1,file2,file3等。我正在执行以下命令
I have created a list of files with names in uppercase alphabets and trying to rename them to files with the same names but in lowercase alphabets. So if i have 20 files with filenames like FILE1, FILE2, FILE3, etc. I want to rename them to file1, file2, file3, etc. respectively. I am executing the below command
[root@host-1-1 files]# find . -name 'FILE*' -exec mv {} `echo {} | tr [:upper:] [:lower:]` \;
但是我从mv命令收到以下错误。有人可以告诉我我在这里想念的吗?
mv: ./ FILE1和 ./FILE1是同一文件
mv: ./ FILE2和 ./FILE2是同一文件
mv:。 / FILE3'和'./FILE3'是相同的文件
mv:'./FILE4'和'./FILE4'是相同的文件
mv:'./FILE5'和'./FILE5 '是同一个文件
mv:'./FILE6'和'./FILE6'是同一个文件
mv:'./FILE7'和'./FILE7'是同一个文件
mv:'./FILE8'和'./FILE8'是同一个文件
mv:'./FILE9'和'./FILE9'是同一个文件
mv:'./FILE10'和'./FILE10'是相同的文件
mv:'./FILE11'和'./FILE11'是相同的文件
mv:'./FILE12'和'./FILE12'是同一文件
mv:'./FILE13'和'./FILE13'是同一文件
mv:'./FILE14'和'./FILE14'是同一文件
mv: './FILE16'和'./FILE16'是相同的文件
mv:'./FILE18'和'./FILE18'是相同的文件
mv:'./FILE20'和'。 / FILE20'是相同的文件
mv:'./FILE15'和'./FILE15'是相同的文件
mv:'./FILE17'和'./FILE17'是相同的文件
mv:'。 / FILE19'和'./FILE19'是相同的文件
[root @ host-1-1文件]#
But i am receiving below errors from mv command. Could someone please tell me what i am missing here?mv: ‘./FILE1’ and ‘./FILE1’ are the same filemv: ‘./FILE2’ and ‘./FILE2’ are the same filemv: ‘./FILE3’ and ‘./FILE3’ are the same filemv: ‘./FILE4’ and ‘./FILE4’ are the same filemv: ‘./FILE5’ and ‘./FILE5’ are the same filemv: ‘./FILE6’ and ‘./FILE6’ are the same filemv: ‘./FILE7’ and ‘./FILE7’ are the same filemv: ‘./FILE8’ and ‘./FILE8’ are the same filemv: ‘./FILE9’ and ‘./FILE9’ are the same filemv: ‘./FILE10’ and ‘./FILE10’ are the same filemv: ‘./FILE11’ and ‘./FILE11’ are the same filemv: ‘./FILE12’ and ‘./FILE12’ are the same filemv: ‘./FILE13’ and ‘./FILE13’ are the same filemv: ‘./FILE14’ and ‘./FILE14’ are the same filemv: ‘./FILE16’ and ‘./FILE16’ are the same filemv: ‘./FILE18’ and ‘./FILE18’ are the same filemv: ‘./FILE20’ and ‘./FILE20’ are the same filemv: ‘./FILE15’ and ‘./FILE15’ are the same filemv: ‘./FILE17’ and ‘./FILE17’ are the same filemv: ‘./FILE19’ and ‘./FILE19’ are the same file[root@host-1-1 files]#
PS:我已经使用过循环并满足了我的要求。我正在努力在find命令中进行理解。
PS: I have already used for loop and have fulfilled my requirement. I am working on my understanding in find command.
推荐答案
YMMV,但我通常会使用重命名
命令,因为它:
YMMV, but I generally reach for the rename
command, because it:
- 很简单,
- 有一个空运行 选项(
-n
) - 如果两个文件重命名为,则不会破坏相同的输出文件。
- is simple,
- has a "dry-run" option (
-n
) - won’t clobber if two files rename to the same output file.
然后您的命令变为:
rename -n 'y/A-Z/a-z/' FILE*
链接某些和。
这篇关于查找命令重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!