例如,我有这些文件:
/Applications/Emacs.app/Contents/Resources/etc/images/custom/README
/Applications/Emacs.app/Contents/Resources/etc/images/ezimage/README
/Applications/Emacs.app/Contents/Resources/etc/images/gnus/README
/Applications/Emacs.app/Contents/Resources/etc/images/gud/README
/Applications/Emacs.app/Contents/Resources/etc/images/icons/README
我想收集所有这些内容并将它们用不同的名称保存在一个目录中,因此它们会变成这样:
/dest/custom_README
/dest/ezimage_README
/dest/gnus_README
/dest/gud_README
/dest/icons_README
我知道find
和xargs
可能对执行此工作很有用,但根据其目录名称不知道如何执行rename
步骤。
有没有人有这方面的想法?谢谢!
答案 0 :(得分:0)
这个怎么样:
[cnicutar@fresh ~]$ sed -r <file 's|.*images/(.*)/(.*)|\1_\2|g'
custom_README
ezimage_README
gnus_README
gud_README
icons_README
或使用awk
:
awk < file -F'/' '{print $(NF-1)"_"$NF}'
答案 1 :(得分:0)
find /Applications/Emacs.app/Contents/Resources/etc/images -name README |
while IFS= read -r filename; do
cp -v "$filename" /dest/"$(basename "$(dirname "$filename")")_README"
done