Created
July 16, 2025 19:37
-
-
Save AllanCapistrano/342d63311c97ad4ad7ea987af3c1236b to your computer and use it in GitHub Desktop.
List directories, and their contents, with repeated prefixes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Lists all directories that contain a hyphen | |
dirs=($(find . -maxdepth 1 -type d -printf "%f\n" | grep '-')) | |
# Extracts prefixes and counts occurrences | |
prefixes=($(for dir in "${dirs[@]}"; do echo "$dir" | cut -d'-' -f1; done)) | |
duplicated_prefixes=$(printf "%s\n" "${prefixes[@]}" | sort | uniq -d) | |
# For each duplicated prefix, lists the corresponding directories | |
for prefix in $duplicated_prefixes; do | |
echo "🔹 Diretórios com prefixo '$prefix':" | |
for dir in "${dirs[@]}"; do | |
if [[ "$dir" == "$prefix"-* ]]; then | |
echo "📁 $dir" | |
ls -l "$dir" | |
echo | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment