Created
June 4, 2017 22:50
-
-
Save i97506051502/ce18919bb6b75d21484696b68e387433 to your computer and use it in GitHub Desktop.
listing all file extensions under directory that is assigned by first argument.
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 | |
set -ue | |
echo -n '' > /tmp/tmp.extensions.list | |
if [[ ${#} -ne 1 ]]; then | |
echo 'Usage:' | |
echo '$ bash listing_all_file_extensions.sh /path/to/directory' | |
else | |
while read directory; do | |
# 方法その一 | |
while read file_path; do | |
file_extension="${file_path##*.}" | |
# 拡張子がないファイルはフルパスが返ってくるのでリストには載せない。 | |
echo "${file_extension}" | grep -v '^/' >> /tmp/tmp.extensions.list | |
done < <(find "${directory}" -type f) | |
# 方法その二 | |
# 拡張子がないファイルはフルパスが返ってくるのでリストには載せない。 | |
# find "${directory}" -type f | sed 's/^.*\.\([^\.]*\)$/\1/' | grep -v '^/' >> /tmp/extensions.list | |
done < <(find "${1}" -type d) | |
fi | |
sort /tmp/tmp.extensions.list | uniq > /tmp/extensions.list | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment