如何通过终端向所有文件添加扩展名


14

我想将.zip扩展名添加到所有文件。我试过了,但是不起作用:

ls | awk '{print $1 " " $1".zip"}' | xargs mv -f

Answers:


5

搜索-几个链接:

  1. 递归地将文件扩展名添加到所有文件-代码日志
  2. 使用bash将文件扩展名添加到文件-代码日志

男子改名:

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...

人工维基:http//en.wikipedia.org/wiki/Man_page


1
thx,基于此我能够做到这一点-ls | xargs -I%mv%%.zip
UAdapter,2011年



4

一个非常简单的方法是:

如果要保留当前扩展名:

for i in *; do mv $i ${i}.zip; done     

如果要替换当前扩展名:

for i in *; do mv $i ${i%.*}.zip; done

0

这应该可以解决问题:

mmv "./*" "./#1.zip"

(尽管我不知道您为什么要这么做...)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.