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

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

我想为所有文件添加 .zip 扩展名。我试过了,但是没有用:

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

答案1

for f in * ; do 
  mv "$f" "$f.zip"
done

答案2

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

不要用xargs那種方式!

答案3

搜索-一些链接:

  1. 递归地将文件扩展名添加到所有文件 - VoidCC
  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

答案4

这应该可以解决问题:

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

(虽然我不知道你为什么要这样做……)

相关内容