-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdfct.sh
executable file
·53 lines (43 loc) · 1.52 KB
/
dfct.sh
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
50
51
52
#!/bin/bash
# Set the default threshold to 10000 if not provided as an argument
THRESHOLD=${1:-10000}
echo "Using file count threshold: $THRESHOLD"
echo ""
# Function to analyze directories recursively
analyze_directory() {
local dir=$1
local level=$2
# Count the total number of files in the current directory (including subdirectories)
file_count=$(find "$dir" -type f | wc -l)
# Calculate the size of the directory
dir_size=$(du -sh "$dir" | cut -f1)
# Display the total number of files and size at this level
if [ "$file_count" -gt "$THRESHOLD" ]; then
echo "Level $level: $dir has $file_count files and is $dir_size in size."
fi
# Check if the file count exceeds the threshold
if [ "$file_count" -gt "$THRESHOLD" ]; then
echo "$dir exceeds the threshold of $THRESHOLD files."
echo "Recommended commands to archive:"
echo " - Zip: zip -r ${dir%/}.zip $dir"
echo " - Tar: tar -cvf ${dir%/}.tar $dir"
echo ""
# Go one level deeper to analyze subdirectories if the current directory exceeds the threshold
for subdir in "$dir"*/; do
if [ -d "$subdir" ]; then
analyze_directory "$subdir" $((level+1))
fi
done
else
# echo "$dir is under the file count threshold."
:
fi
}
# Loop through all top-level directories
for dir in */; do
if [ -d "$dir" ]; then
echo "Analyzing top-level directory: $dir"
analyze_directory "$dir" 1
echo ""
fi
done