Add disk_cleanup_linux
This commit is contained in:
parent
db8946f28e
commit
5ce5c4bea9
82
disk_cleanup_linux
Normal file
82
disk_cleanup_linux
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
|
||||||
|
# Function to list directories
|
||||||
|
list_directories() {
|
||||||
|
local dir=$1
|
||||||
|
echo "Listing directories under: $dir"
|
||||||
|
du -h --max-depth=1 "$dir" 2>/dev/null | sort -hr
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to delete a directory
|
||||||
|
delete_directory() {
|
||||||
|
local dir_to_delete=$1
|
||||||
|
echo "Are you sure you want to delete the directory: $dir_to_delete? (y/n)"
|
||||||
|
read -r confirmation
|
||||||
|
if [[ $confirmation == "y" ]]; then
|
||||||
|
rm -rf "$dir_to_delete"
|
||||||
|
echo "Deleted: $dir_to_delete"
|
||||||
|
else
|
||||||
|
echo "Deletion cancelled."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to list largest files in a directory
|
||||||
|
list_largest_files() {
|
||||||
|
local dir=$1
|
||||||
|
echo "Listing largest files in: $dir"
|
||||||
|
find "$dir" -type f -exec du -h {} + | sort -hr | head -n 10
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to display the menu
|
||||||
|
display_menu() {
|
||||||
|
echo "Menu Options:"
|
||||||
|
echo "1. List directories"
|
||||||
|
echo "2. Delete a directory"
|
||||||
|
echo "3. Dig into a directory to find largest files"
|
||||||
|
echo "4. Quit"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main function to manage disk cleanup
|
||||||
|
disk_cleanup() {
|
||||||
|
local current_dir="/home"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
display_menu
|
||||||
|
read -r choice
|
||||||
|
|
||||||
|
case $choice in
|
||||||
|
1)
|
||||||
|
list_directories "$current_dir"
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
echo "Enter the directory path to delete (relative to $current_dir):"
|
||||||
|
read -r user_input
|
||||||
|
if [[ -d "$current_dir/$user_input" ]]; then
|
||||||
|
delete_directory "$current_dir/$user_input"
|
||||||
|
else
|
||||||
|
echo "Invalid directory. Please try again."
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
echo "Enter the directory path to dig into (relative to $current_dir):"
|
||||||
|
read -r user_input
|
||||||
|
if [[ -d "$current_dir/$user_input" ]]; then
|
||||||
|
list_largest_files "$current_dir/$user_input"
|
||||||
|
else
|
||||||
|
echo "Invalid directory. Please try again."
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
4)
|
||||||
|
echo "Exiting..."
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid option. Please try again."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start the disk cleanup process
|
||||||
|
disk_cleanup
|
||||||
Loading…
x
Reference in New Issue
Block a user