-
Notifications
You must be signed in to change notification settings - Fork 25
/
empty-trash
executable file
·54 lines (52 loc) · 1.89 KB
/
empty-trash
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
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
set -euf -o pipefail
##
# Empty the trash on a Unix system.
#
# This deletes all the files in a user's typical trash directory:
#
# ~/.Trash/ (typical on OSX)
# ~/.local/share/Trash/info/ (typical on Ubuntu)
# ~/.local/share/Trash/files/ (typical on Ubuntu)
#
# Example:
#
# empty-trash
#
# The implementation uses `find` and the `-delete` flag, for
# the most efficiency and security, given current GNU tools.
#
# The implementation also uses `-mindepth` to ensure the trash
# directories are not accidentally deleted, and also to solve
# the warning "relative path potentially not safe".
#
# ## Details
#
# As far as we know, using `find` and the `-delete` flag is the most
# efficient and secure way to delete files that works on current GNU
# systems, without needing to use any filesystem-specific knowledge.
#
# This is more efficient than using ‘-exec’ or ‘-execdir’ actions,
# because `-delete` doesn't fork a new process using `exec` or `rm`.
# This is normally more efficient than xargs for the same reason.
#
# The file deletion is performed from the directory containing the
# entry to be deleted, so the `-delete` action has the same security
# advantages as using an equivalent `-execdir` action has.
#
# The `-delete` action is not completely portable, but the only other
# possibility as secure is using `-execdir` which is no more portable.
#
# The most efficient portable way is `-exec ...+`, but is insecure and
# isn't supported by versions of GNU findutils prior to 4.2.12.
#
# For details about deleting files, and how to do it effectively:
# http://www.gnu.org/software/findutils/manual/html_node/find_html/Deleting-Files.html
#
# Contact: Joel Parker Henderson ([email protected])
# License: GPL
# Updated: 2015-08-05
##
for i in $HOME/.Trash/ $HOME/.local/share/Trash/files/ $HOME/.local/share/Trash/info/; do
test -d "$i" && find "$i" -mindepth 1 -delete
done