查找某个目录下使用的所有文件扩展名(递归)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查找某个目录下使用的所有文件扩展名(递归)相关的知识,希望对你有一定的参考价值。
# Not sure, what this is good for - however this is asked sometimes. # I specifically exclude "dotfiles" and only consider files of the form "foo.bar" (i.e. we # don't consider filenames without an "inner dot" at all) find . -type f -name '[^.]*.*' \ -exec bash -c 'printf "%s\n" ${@##*.}' _ {} + | sort -u # (or ... | sort | uniq, in case the sort lacks -u, which is a GNUism) # Of course it's trivial to do it non-recursively: for f in *.*; do printf "%s\n" "${f##*.}"; done | sort -u # or recursively again, with a bash4 associative array, including # a count for each extension (no sorting here): unset a; declare -A a while IFS= read -r ext; do ((a[$ext]++)) done < <(find . -type f -name '[^.]*.*' \ -exec bash -c 'printf "%s\n" ${@##*.}' _ {} +) for ext in "${!a[@]}"; do printf "'%s' (%s)\n" "$ext" "${a[$ext]}" done # NOTE: all methods above fail, if an extension contains embedded newlines.
以上是关于查找某个目录下使用的所有文件扩展名(递归)的主要内容,如果未能解决你的问题,请参考以下文章