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 -r
with-f
is also a good idea. – Mio Rin Apr 07 '19 at 05:35$TMP/$folder
before deleting$folder
and have it abort/skip the deletion if$TMP/$folder
isn't there. – Mio Rin Apr 07 '19 at 05:41/
will still exist. – Sparhawk Apr 07 '19 at 06:03du
to 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