递归查找具有相同名称的文件(bash4,关联数组)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了递归查找具有相同名称的文件(bash4,关联数组)相关的知识,希望对你有一定的参考价值。
# Find files with duplicate names. Generate a file ("dfn") with "mv" commands # to move the duplicates to a subdirectory ("DUPS") with mangled filename. # (e.g. multiple files "foo.txt" become foo_1.txt, foo_2.txt and so on). # NOTE: Even after sourcing dfn (and thus moving the files) there may be # duplicate names, since there may already have been a "foo_1.txt" in the first place (and # so now you have 2). So the scriptlet has to be called multiple times (i.e. # until dfn is empty) unset fl; declare -A fl while IFS=$' 01' read -r ff f; do if [[ ${fl[$f]} ]]; then (( fl[$f]++ )); sfx="${f##*.}" printf 'mv -- "%s" DUPS/"%s" # Duplicate Filename: "%s" (%i) ' "$ff" "${f%.*}_${fl[$f]}.${sfx}" "$f" "${fl[$f]}" else fl[$f]=0; fi done < <(find . -type f -exec bash -c 'for file in "[email protected]"; do printf "%s 01%s " "$file" "${file##*/}"; done' _ {} +) >dfn
以上是关于递归查找具有相同名称的文件(bash4,关联数组)的主要内容,如果未能解决你的问题,请参考以下文章
如何在 C++ 中递归查找具有 Unicode 名称的文件?
将awk模式应用于具有相同名称的所有文件,将每个文件输出到新文件