File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
projects/LinuxSystemOps/Filesystem Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ # Usage: bash $0
3+ # Author: dgden
4+ # Create Date: 2021/4/25
5+ # Create Time: 13:57
6+ # Description: remove files or directories safely on Linux
7+
8+ if [[ -f " $HOME " /.bashrc ]]; then
9+ bash_rc_path=" $HOME " /.bashrc
10+ elif [[ -f " $HOME " /.bash_profile ]]; then
11+ bash_rc_path=" $HOME " /.bash_profile
12+ fi
13+
14+ \c p " $bash_rc_path " " ${bash_rc_path} _$( date +%Y%m%d%H%M%S) ~"
15+
16+ cat >> " $bash_rc_path " << 'eof '
17+ # enable trash bin for bash
18+ if [ ! -d ~/.trash ]; then
19+ mkdir -p ~/.trash
20+ fi
21+
22+ alias rm=trash
23+ alias r=trash
24+ alias rl='ls ~/.trash'
25+ alias ur=undelete_file
26+ alias cr=clear_trash
27+ undelete_file() {
28+ mv -i ~/.trash/"$*" ./
29+ }
30+
31+ trash() {
32+ mv "$@" ~/.trash/
33+ }
34+
35+ clear_trash() {
36+ read -pr "clear sure?[n]" confirm
37+ [ "$confirm" == 'y' ] || [ "$confirm" == 'Y' ] && /usr/bin/rm -rf ~/.trash/*
38+ }
39+ # end
40+
41+
42+ eof
43+
44+ # shellcheck source=$HOME/.bashrc
45+ source " $HOME " /.bashrc
46+
47+ echo " Tips: use a separate disk or mount point to serve the important files, so you can use extundelete easily."
48+
49+ # shellcheck disable=SC2028
50+ echo ' You can use "\rm -rf path" to delete directly.'
You can’t perform that action at this time.
0 commit comments