Search This Blog

Thursday, July 22, 2010

Precaution to take before deleting file through script.

Here i m highlighting the best practice to delete a file when there is a variable involved as a file name.

echo "Enter file or folder to delete from tmp"
read input
if [ ! -f "/tmp/$input" ]
echo "File Doesnt Exist"
rm -f "/tmp/$input"

rm -f, --force
ignore nonexistent files, never prompt

No comments:

Post a Comment