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

Popular posts from this blog

3.Write a shell script to print below pattern 1 1 2 1 1 3 3 1