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

UAd*_*ter 16 command-line bash file-extension

我想为所有文件添加 .zip 扩展名。我试过这个,但它不起作用:

ls | awk '{print $1 " " $1".zip"}' | xargs mv -f
Run Code Online (Sandbox Code Playgroud)

elm*_*cha 23

for f in * ; do 
  mv "$f" "$f.zip"
done
Run Code Online (Sandbox Code Playgroud)


Ado*_*obe 18

rename 's/$/\.zip/' *
Run Code Online (Sandbox Code Playgroud)

不要xargs用于那个!

  • 好吧 - 没有理由! (4认同)

dmx*_*dmx 6

一个非常简单的方法是:

如果您想保留当前扩展名:

for i in *; do mv $i ${i}.zip; done     
Run Code Online (Sandbox Code Playgroud)

如果你想替换当前的扩展:

for i in *; do mv $i ${i%.*}.zip; done
Run Code Online (Sandbox Code Playgroud)


use*_*687 5

搜索 - 几个链接:

  1. 递归地将文件扩展名添加到所有文件 - VoidCC
  2. 使用 bash 向文件添加文件扩展名_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...
Run Code Online (Sandbox Code Playgroud)

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