0

例如,我有这些文件:

/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根据其目录名称执行该步骤。

有人对此有想法吗?谢谢!

4

2 回答 2

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}'
于 2012-11-24T07:40:08.093 回答
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
于 2012-11-24T13:15:25.653 回答