-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount
More file actions
executable file
·49 lines (42 loc) · 917 Bytes
/
count
File metadata and controls
executable file
·49 lines (42 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Count files according to their extension
recursive=false
summary=false
while getopts "rsh" opt; do
case $opt in
r)
recursive=true
;;
s)
summary=true
;;
h)
echo " -r"
echo " Recursive"
echo " -s"
echo " Summary of each subdirectory"
exit 0
;;
esac
done
dirs=()
# If summary, add each subdirectory
if $summary; then
for dir in ./*; do
if [[ -d "$dir" ]]; then
dirs+=("$dir")
fi
done
# Else, add only the current directory
else
dirs+=(".")
fi
if $recursive; then
maxdepth=""
else
maxdepth="-maxdepth 1"
fi
for dir in "${dirs[@]}"; do
echo $dir
find "$dir" $maxdepth -type f -printf "%f\n" | egrep --invert-match '^\.' | rev | cut -d . -f1 | rev | sort | uniq -ic | sort -rn
done