简体   繁体   English

如何收集所有自述文件并在文件夹中重命名它们?

[英]How to collect all README files and rename them in a folder?

For example, I have these files: 例如,我有以下文件:

/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

I want to collect all of them and save them with different names in one directory, so they become something like this: 我想收集所有这些文件,并以不同的名称保存在一个目录中,这样它们就变成了这样:

/dest/custom_README
/dest/ezimage_README
/dest/gnus_README
/dest/gud_README
/dest/icons_README

I know find and xargs might be useful to do this job but don't know how to do the rename step according to its directory name. 我知道findxargs可能对完成此工作很有用,但不知道如何根据其目录名称执行rename步骤。

Does anyone have ideas about this? 有人对此有想法吗? Thanks! 谢谢!

How about this: 这个怎么样:

[cnicutar@fresh ~]$ sed -r <file 's|.*images/(.*)/(.*)|\1_\2|g'
custom_README
ezimage_README
gnus_README
gud_README
icons_README

Or using awk : 或使用awk

awk < file -F'/' '{print $(NF-1)"_"$NF}'
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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM