在文件夹下/home/files
我们有以下文件
VER_3all_servers_home\server383_232.35.35.341
VER_3all_servers_home\server323_232.35.35.342
VER_3all_servers_home\server313_232.35.35.343
VER_3all_servers_home\server303_232.35.35.344
VER_3all_servers_home\server381_232.35.35.345
VER_3all_servers_home\server380_232.35.35.346
3all_servers_home\
我们要重新编辑文件,方法是从下面的所有文件中删除单词“ ”/home/files
所以文件看起来像这样
VER_server383_232.35.35.341
VER_server323_232.35.35.342
VER_server313_232.35.35.343
VER_server303_232.35.35.344
VER_server381_232.35.35.345
VER_server380_232.35.35.346
有什么建议如何执行此方法吗?
答案1
你可以做:
for f in /home/files/*3all_servers_home*; do
mv -- "$f" "${f//3all_servers_home\\}"
done
该格式将从变量中${var//glob}
删除 glob 的所有匹配项。glob
var
或者,如果您有perl-rename
(我不记得它在 Red Hat 上的名称,它将是rename
、prename
或 之一perl-rename
):
rename 's/3all_servers_home\\//' /home/files/*3all_servers_home*