Skip to content

Instantly share code, notes, and snippets.

@AllanCapistrano
Created July 16, 2025 19:37
Show Gist options
  • Save AllanCapistrano/342d63311c97ad4ad7ea987af3c1236b to your computer and use it in GitHub Desktop.
Save AllanCapistrano/342d63311c97ad4ad7ea987af3c1236b to your computer and use it in GitHub Desktop.
List directories, and their contents, with repeated prefixes
#!/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