How to delete folders that might-be semi duplicated?
E.g., there can be two versions A and B of each folderName. Either A, B or both A and B:
A
B
folderName
B_folderName1 A_folderName2 A_folderName3 B_folderName3
I want to choose preferred version A and delete B, or just keep B if A is not available. Following example above the expected output is:
B_folderName1 A_folderName2 A_folderName3
Thanks!
Loop through B_*, and delete each of those for which a corresponding A_* exists.
B_*
A_*
for d in B_*/; do if [[ -e A_${d#B_} ]]; then echo rm -r "$d" fi done
Drop echo if the output looks good.
echo
2.1m questions
2.1m answers
60 comments
57.0k users