background file removal

This commit is contained in:
q
2015-01-30 22:51:31 +02:00
parent 8d29bc6eda
commit 683b00ba46
2 changed files with 25 additions and 0 deletions

1
bin/rm_bg Symbolic link
View File

@@ -0,0 +1 @@
../rmbg

24
rm_bg Executable file
View File

@@ -0,0 +1,24 @@
#!/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
d=$( readlink -nf $( dirname "$f" ) )/.rmgb.$$
mkdir -p "$d"
mv $f "$d"/
tempfolders+=( "$d" )
done
(
for (( i=0; $i<${#tempfolders[@]}; i++ )); do
rm -rf "${tempfolders[$i]}"
done
) &