I'm new in BASH and I'm trying to make a simple script. I would like to run the script from a different directory, and then the script should delete all my files in my current directory. (ONLY FILES) So the function is:
eraseAllFiles()
{   
    rm * 
    echo "Files deleted!"
    sleep 1.3
}
So the command rm * delete all my files but then I get this error:
cannot remove 'XXXXX': is a directory.
My question is how can I avoid this error?
Instead of rm use find -type f to delete only files:
eraseAllFiles() {   
    find . -maxdepth 1 -type f -delete 
    echo "Files deleted!"
    sleep 1.3
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With