56 lines
1.5 KiB
Bash
56 lines
1.5 KiB
Bash
#!/bin/bash
|
|
|
|
# Initialize variables
|
|
auto_confirm=false
|
|
|
|
# Parse arguments for the folder path and the -y option
|
|
while [[ "$#" -gt 0 ]]; do
|
|
case "$1" in
|
|
-y) auto_confirm=true ;;
|
|
*) folder_path="$1" ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# If no folder path is provided, prompt the user for it
|
|
if [ -z "$folder_path" ]; then
|
|
read -p "Enter the path to the folder: " folder_path
|
|
fi
|
|
|
|
# Check if the provided path is valid
|
|
if [ ! -d "$folder_path" ]; then
|
|
echo "Invalid folder path. Please provide a valid directory."
|
|
exit 1
|
|
fi
|
|
|
|
# Find all .Trash-1000 directories within the provided path
|
|
echo "Searching for .Trash-1000 folders in $folder_path..."
|
|
|
|
trash_folders=$(find "$folder_path" -type d -name ".Trash-1000")
|
|
|
|
if [ -z "$trash_folders" ]; then
|
|
echo "No .Trash-1000 folders found."
|
|
else
|
|
echo "Found the following .Trash-1000 folders:"
|
|
echo "$trash_folders"
|
|
echo
|
|
|
|
# Ask for confirmation before deletion if -y is not provided
|
|
if [ "$auto_confirm" = false ]; then
|
|
read -p "Do you really want to delete all these folders? (y/n): " confirmation
|
|
if [[ "$confirmation" != "y" && "$confirmation" != "Y" ]]; then
|
|
echo "Deletion canceled."
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
# Loop through each found folder and delete it
|
|
while IFS= read -r folder; do
|
|
echo "Deleting folder: $folder"
|
|
rm -rf "$folder"
|
|
echo "Deleted $folder"
|
|
done <<< "$trash_folders"
|
|
|
|
echo "All .Trash-1000 folders have been deleted."
|
|
fi
|