Last active
January 6, 2025 10:21
-
-
Save vijinho/a8e2838b5408548ba03c to your computer and use it in GitHub Desktop.
List the file extensions found for a given directory tree, default current directory
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 | |
# Function to display usage information | |
usage() { | |
echo "Usage: $0 [-d | --directory] <directory>" | |
echo " -d, --directory Specify the directory to search (default: current directory)" | |
exit 1 | |
} | |
# Default directory is the current directory | |
DIR="." | |
# Parse command-line arguments | |
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in | |
-d | --directory ) | |
shift; DIR="$1" | |
;; | |
*) | |
usage | |
;; | |
esac; shift; done | |
if [[ "$1" == '--' ]]; then shift; fi | |
# Check if directory exists | |
if [[ ! -d "$DIR" ]]; then | |
echo "Error: Directory '$DIR' does not exist." | |
usage | |
fi | |
# Find file extensions used in the specified directory and its subdirectories | |
find "$DIR" -type f | awk -F. '{print $NF}' | sort -u |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment