Answers:
感谢Peter van der Heijden,以下是适用于其中带有空格的文件名的一种:
for f in * ; do mv -- "$f" "PRE_$f" ; done(“-”需要以破折号开头的文件才能成功,否则其名称将被解释为mv命令的开关)
ls命令更改为*,并将参数括在双引号中mv,则它将适用于包含空格的文件。
                    rename一直帮助我非常轻松地处理多个文件重命名。
                    要为文件(目录)添加前缀或后缀,可以通过xargs使用简单而强大的方法:
ls | xargs -I {} mv {} PRE_{}
ls | xargs -I {} mv {} {}_SUF它使用xargs的参数替换选项:-I。您可以从手册页中获取更多详细信息。
ls *.old | xargs -I {} mv {} PRE_{}
                    要使用util-linux rename(相对于prenameDebian和某些其他系统的perl变体)向当前目录中的所有文件和文件夹添加前缀,您可以执行以下操作:
rename '' <prefix> *这将查找空字符串的第一个匹配项(立即发现),然后用您的前缀替换该匹配项,然后将其余文件名粘贴到该文件名的末尾。做完了
util-linux在Debian Stretch上似乎提供了这一点/usr/bin/rename.ul。
                    这是您可以使用的简单脚本。我喜欢使用非标准模块File::chdir来处理管理cd操作,因此要按原样使用此脚本,您需要安装它(sudo cpan File::chdir)。
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
use File::chdir; # allows cd-ing by use of $CWD, much easier but needs CPAN module
die "Usage: $0 dir prefix" unless (@ARGV >= 2);
my ($dir, $pre) = @ARGV;
opendir(my $dir_handle, $dir) or die "Cannot open directory $dir";
my @files = readdir($dir_handle);
close($dir_handle);
$CWD = $dir; # cd to the directory, needs File::chdir
foreach my $file (@files) {
  next if ($file =~ /^\.+$/); # avoid folders . and ..
  next if ($0 =~ /$file/); # avoid moving this script if it is in the directory
  move($file, $pre . $file) or warn "Cannot rename file $file: $!";
}在我的系统上,我没有rename命令。这是一个简单的衬板。它以递归方式查找所有HTML文件,并prefix_在其名称前添加:
for f in $(find . -name '*.html'); do mv "$f" "$(dirname "$f")/prefix_$(basename "$f")"; donefind你也可以执行命令,没有必要为一个循环:stackoverflow.com/a/33297439/2351568