Answers:
列出所有目录公用文件的所有名称(而不是路径)。
dirs=( "A dir" "B dir" "C dir" "D dir" )
find "${dirs[@]}" -maxdepth 1 -type f -name "*" -printf '%f\n' |
sort | uniq -c | sed -n "s/^ *${#dirs[@]} //p"
或将其称为脚本文件或函数,并以目录作为参数。
find "$@" -maxdepth 1 -type f -name "*" -printf '%f\n' |
sort | uniq -c | sed -n "s/^ *$# //p"
您可以显示一个名称列表,这些名称按它们出现在其中的目录数排序。
find */ | # traverse all the template directories
sort -t / -k 2 | # sort, ignoring the first field
tr '/' '\t' | # turn / into tabs
uniq -f 1 -c | # count duplicates, ignoring the first field
tr '\t' '/' | # turn tabs back into /
sort -t / -s -k 1n # sort by the number of occurrences