29 lines
556 B
Bash
Executable File
29 lines
556 B
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
function helpexit() {
|
|
echo Delete files in background, by moving the to a temp folder first.
|
|
echo This command is always recursive!
|
|
exit
|
|
}
|
|
|
|
[[ -z "$1" ]] && helpexit
|
|
[[ "$1" = "-h" ]] && helpexit
|
|
|
|
tempfolders=()
|
|
for f in "$@"; do
|
|
[[ -e "$f" ]] || {
|
|
echo "$f" does not exist
|
|
continue
|
|
}
|
|
d=$( readlink -nf $( dirname "$f" ) )/.rm_bg.$$
|
|
mkdir -p "$d"
|
|
mv "$f" "$d"/
|
|
tempfolders+=( "$d" )
|
|
done
|
|
|
|
(
|
|
for (( i=0; $i<${#tempfolders[@]}; i++ )); do
|
|
rm -rf "${tempfolders[$i]}"
|
|
done
|
|
) &
|