-
Notifications
You must be signed in to change notification settings - Fork 9
/
recyclebin
42 lines (38 loc) · 1004 Bytes
/
recyclebin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /bin/bash
#
# Utility function for listing the trash can, for there is no way to sort
# the files by deletion date. Written by davidhcefx, 2017.12.04.
help(){
echo "Syntax: "
echo " recyclebin list - List all, sorted by deletion date."
echo " recyclebin recover [name] - Recover a file to ~/."
echo " recyclebin remove [2017-12] - Remove all files deleted in [date].
"
}
tmp=/tmp/recycle.tmp
cd ~/.local/share/Trash/files
case $1 in
list)
stat -c "%.19z - %n" * | sort -t'-'
;;
recover)
if (( $# < 2 )); then help; exit; fi
mv $2 ~/
;;
remove)
if (( $# < 2 )); then help; exit; fi
stat -c "%.7z /%n" * | grep ^$2 > $tmp
cat $tmp
echo ""
read -p "Are you sure you want to remove these files? [y/n] " -n 1 ch
if [ $ch == y ]; then
while read line; do
rm -r "${line#*/}"
done < $tmp
fi
rm $tmp
;;
*)
help
;;
esac