sometimes using rm -rf in script could be catastrophic
example
rm -rf $TMP/$folder
when TMP and $folder are without any value , it will actually
removing all under "/"
so I am asking how to use the rm -rf in the scripts so it will be safe?
sometimes using rm -rf in script could be catastrophic
example
rm -rf $TMP/$folder
when TMP and $folder are without any value , it will actually
removing all under "/"
so I am asking how to use the rm -rf in the scripts so it will be safe?
$TMP and $TMP/$folder are directories$TMP and $TMP/$folder are different (imagine folder="" or folder="/")$TMP/$folder is writableif [ -d "$TMP" ]\
&& [ -d "$TMP/$folder" ]\
&& [ "$(readlink -e "$TMP")" != "$(readlink -e "$TMP/$folder")" ]\
&& [ -w "$TMP/$folder" ]; then
rm -rf "$TMP/$folder"
else
echo "Could not delete folder \"$TMP/$folder\", TMP=$TMP, folder=$folder" >&2
fi
rm -rwith-fis also a good idea. – Mio Rin Apr 07 '19 at 05:35$TMP/$folderbefore deleting$folderand have it abort/skip the deletion if$TMP/$folderisn't there. – Mio Rin Apr 07 '19 at 05:41/will still exist. – Sparhawk Apr 07 '19 at 06:03duto verify that the target directory is not larger than you expect. – John1024 Apr 07 '19 at 06:04/or./– ctrl-alt-delor Apr 07 '19 at 10:02