-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleaner.sh
executable file
·37 lines (28 loc) · 961 Bytes
/
cleaner.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
#!/bin/bash
# Function to convert bytes to gigabytes
bytes_to_gb() {
echo "scale=2; $1 / 1024 / 1024 / 1024" | bc
}
# Prompt the user for the directory containing the Rust projects
read -p "Enter the directory containing the Rust projects: " PROJECTS_DIR
# Check if the directory exists
if [ ! -d "$PROJECTS_DIR" ]; then
echo "Directory $PROJECTS_DIR does not exist."
exit 1
fi
# Calculate initial disk usage
initial_usage=$(du -sb "$PROJECTS_DIR" | awk '{print $1}')
# Iterate over all subdirectories in the projects directory
for dir in "$PROJECTS_DIR"/*/; do
if [ -d "$dir" ]; then
echo "Cleaning project in directory: $dir"
(cd "$dir" && cargo clean)
fi
done
# Calculate final disk usage
final_usage=$(du -sb "$PROJECTS_DIR" | awk '{print $1}')
# Calculate freed space
freed_space=$(($initial_usage - $final_usage))
freed_space_gb=$(bytes_to_gb $freed_space)
# Display the freed space
echo "Total freed space: $freed_space_gb GB"