Skip to content

Instantly share code, notes, and snippets.

@naranyala
Last active August 8, 2023 03:09
Show Gist options
  • Save naranyala/1b29f82c7c90b64567652820e2a26515 to your computer and use it in GitHub Desktop.
Save naranyala/1b29f82c7c90b64567652820e2a26515 to your computer and use it in GitHub Desktop.
display file metadata. including text file, image, audio, and video.
#!/bin/bash
# Function to display metadata for a given file
show_metadata() {
if [[ -f "$1" ]]; then
echo "File: $1"
exiftool "$1"
echo "---------------------------------------------"
else
echo "Error: File '$1' not found or not a regular file."
fi
}
# Check if ExifTool is installed
check_exiftool_installation() {
if ! command -v exiftool &> /dev/null; then
echo "ExifTool is not installed. Do you want to install it?"
echo "(Note: This script supports 'apt' for Debian-based systems and 'pkg' for Termux.)"
read -p "Do you want to proceed with installation? (y/n): " choice
case "$choice" in
[Yy]* )
install_exiftool
;;
[Nn]* )
echo "ExifTool is required to run this script. Exiting."
exit 1
;;
* )
echo "Invalid choice. Exiting."
exit 1
;;
esac
fi
}
# Install ExifTool using apt (Debian-based systems)
install_exiftool_apt() {
sudo apt update
sudo apt install -y exiftool
}
# Install ExifTool using pkg (Termux)
install_exiftool_pkg() {
pkg update
pkg install -y exiftool
}
# Check for correct number of arguments
if [ $# -lt 1 ]; then
echo "Usage: $0 <file1> [<file2> <file3> ...]"
exit 1
fi
# Check ExifTool installation
check_exiftool_installation
# Loop through each provided file and display metadata
for file in "$@"; do
show_metadata "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment