您好,感谢您的阅读!
我有这样的清单:
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
(它更长)我想将每个图像(“最新?cb = 20150402221631”是png图像)复制到另一个文件夹并将其重命名为2级别目录的名称,如下所示:
user@laptop:~/lol$ find ./ \( -iname 'latest*' \) -type f -printf "%p\n"
/leagueoflegends/images/e/e6/CaitlynSquare.png/revision/latest?cb=20150402215548
/leagueoflegends/images/e/ef/WillumpSquare.png/revision/latest?cb=20150402222523
/leagueoflegends/images/d/d8/MorganaSquare.png/revision/latest?cb=20150402220702
/leagueoflegends/images/d/d1/UdyrSquare.png/revision/latest?cb=20150402221631
如果可能的话,删除Square。
latest?cb=20150402221631 --> to --> UdyrSquare.png
答案 0 :(得分:0)
如果您的发行版上有Perl rename
命令(可能是prename
或perl-rename
),则可以使用正则表达式重命名文件。它可以从输入中读取文件名:
find . -iname 'latest*' -type f | rename -n ':Square.png.*cb=\d+:.png:'
或者,更具体地说:
find . -iname 'latest*' -type f | rename -n 's:Square.png/[^/]*/latest\?cb=\d+:.png:'
例如:
$ cat foo.txt| perl-rename -n 's:Square.png/[^/]*/latest\?cb=\d+:.png:'
/leagueoflegends/images/e/e6/CaitlynSquare.png/revision/latest?cb=20150402215548 -> /leagueoflegends/images/e/e6/Caitlyn.png
/leagueoflegends/images/e/ef/WillumpSquare.png/revision/latest?cb=20150402222523 -> /leagueoflegends/images/e/ef/Willump.png
/leagueoflegends/images/d/d8/MorganaSquare.png/revision/latest?cb=20150402220702 -> /leagueoflegends/images/d/d8/Morgana.png
/leagueoflegends/images/d/d1/UdyrSquare.png/revision/latest?cb=20150402221631 -> /leagueoflegends/images/d/d1/Udyr.png
-n
选项用于测试命令。一旦对结果感到满意,就可以在没有结果的情况下运行。
答案 1 :(得分:0)
使用bash:
附加:
| while read -r line; do echo mv -v "$line" "${line%Square*}.png"; done
如果一切正常,请删除echo
。