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

10.Write a shell script to count the number words,lines,character from given file accept file name from commandline.

2.Write a shell script to compile all C files and delete those files having errors.