Link 分隔词

Link separated words

我想知道是否有程序或脚本可以 link 用点(或其他标点符号)分隔文件名中的单词。 例子: 怎么样 you.pdf >>> 怎么样.you.pdf
我没有很好地解释自己,我正在寻找一个 bash 可以重命名文件名的脚本

sed 是你的帮手。

例如:

echo "How are you.pdf" | sed 's/ /./g'

sed命令分为command/1st argument/2nd argument/command

在我们的示例中:

s - search

[space] - the space character

. - the dot character to replace

g - do this globally and not only for the first occurrence

假设您在变量中有 How are you.pdf,您可以使用 parameter expansions:

% a="How are you.pdf"
% echo "${a// /.}"
How.are.you.pdf

以上是 bash 扩展,在 POSIX shell 中不起作用。在这种情况下,将需要 sed 或模拟。

重命名当前目录下的所有文件:

for a in *; do
  [ -f "$a" ] || continue
  mv -- "$a" "${a// /.}"
done

有一个名为 perl-rename sometimes called rename - not to be confused with rename from util-linux 的工具。

此工具采用 Perl 表达式并相应地重命名:

perl-rename 's/ /./g' *

以上将重命名当前目录中的所有文件/目录以添加句点替换空格:

How are you.pdf      -> How.are.you.pdf
This is another.file -> This.is.another.file

You can try the regex online