20.Write a shell script to delete all text files from the directory
#!/bin/bash
# Specify the directory (or use the current directory)
dir=${1:-.}
# Confirm deletion with the user
read -p "Are you sure you want to delete all .txt files in the directory $dir? (y/n): " confirm
if [[ $confirm == [yY] ]]; then
# Delete all .txt files in the specified directory
rm -f "$dir"/*.txt
echo "All .txt files deleted from $dir."
else
echo "Operation canceled."
fi
Comments
Post a Comment