|
2 | 2 |
|
3 | 3 | skip important files and dirs during rm;
|
4 | 4 |
|
5 |
| -in the past, users have reported success in deleting their home dir, root dir, |
6 |
| -and much more; skip-rm helps you prevent such accidental deletions by checking |
7 |
| -filenames; you specify which files to and not to delete, and skip-rm does the |
8 |
| -rest for you; |
| 5 | +in the past, users have frequently reported success in deleting their home dir, |
| 6 | +root dir, and much more; skip-rm helps prevent such accidental deletions using |
| 7 | +filename checks; you specify which files to and not to delete and skip-rm does |
| 8 | +the rest for you; |
9 | 9 |
|
10 | 10 | ## install
|
11 | 11 |
|
12 |
| -skip-rm has a single script file and a few config files; |
| 12 | +this tool has several implementations: |
13 | 13 |
|
14 |
| -the script file shall be installed into a dir listed in envar `PATH`: |
| 14 | +- `bash/README.md`; |
15 | 15 |
|
16 |
| - cp skip-rm /usr/bin/ |
| 16 | +- `go/README.md`; |
17 | 17 |
|
18 |
| -the config files shall be installed into either system or user config dir; |
19 |
| -system config dir is `/etc/skip-rm`; user config dir is `~/.config/skip-rm`; |
20 |
| -user config has higher priority; |
| 18 | +these implementations are independent, and you can choose any one of them; but |
| 19 | +beware there may be minor differences among these implementations, which means |
| 20 | +they may not give exactly the same behavior; double check the source code, and |
| 21 | +make sure you understand what is happening before use; open an issue if needed; |
21 | 22 |
|
22 |
| -to install into system config dir: |
| 23 | +the bash implementation has longer history and tends to be more stable; but it |
| 24 | +is very slow when there are a lot of filenames; the go implementation is newer |
| 25 | +and faster, but has a higher chance of malfunction; you are advised to do some |
| 26 | +dryrun (using a fake `rm`) before deploying this tool so as to not have a pity; |
23 | 27 |
|
24 |
| - cp -r config/skip-rm /etc/ |
25 |
| - |
26 |
| -to install into user config dir: |
27 |
| - |
28 |
| - cp -r config/skip-rm ~/.config/ |
29 |
| - |
30 |
| -## usage |
31 |
| - |
32 |
| -to test with the default config (do not test with important files): |
33 |
| - |
34 |
| - skip-rm {files-to-remove} |
35 |
| - |
36 |
| -if everything is good, alias `rm` to `skip-rm`: |
37 |
| - |
38 |
| - alias rm='skip-rm' |
39 |
| - |
40 |
| -`skip-rm` is designed as a wrapper of and a drop-in replacement for `rm`; it is |
41 |
| -recommened to alias `rm` to `skip-rm` in bashrc; then simply run `rm` as usual, |
42 |
| -knowing important files and dirs will be protected from deletion; |
43 |
| - |
44 |
| -## config |
45 |
| - |
46 |
| -the main config file is `skip-rm.conf`, in json format: |
47 |
| - |
48 |
| - { |
49 |
| - "command": "/bin/rm", |
50 |
| - "matcher": "glob", |
51 |
| - "mode": "blacklist", |
52 |
| - "blacklist": "~/.config/skip-rm/black.list", |
53 |
| - "whitelist": "~/.config/skip-rm/white.list" |
54 |
| - } |
55 |
| - |
56 |
| -available config options are: |
57 |
| - |
58 |
| -- *command*: the builtin rm command; |
59 |
| - |
60 |
| -- *matcher*: filename matcher: |
61 |
| - |
62 |
| - - *string*: match string verbatim; |
63 |
| - |
64 |
| - - *glob*: match with glob patterns: |
65 |
| - |
66 |
| - - `?` matches any single char (excluding slash `/`); |
67 |
| - |
68 |
| - - `*` matches any string (excluding slash `/`); |
69 |
| - |
70 |
| - - `**` matches any string (including slash `/`); |
71 |
| - |
72 |
| - - `[...]`: matches any one of the enclosed characters; |
73 |
| - |
74 |
| - - *regex*: match with regular expressions; |
75 |
| - |
76 |
| -- *mode*: how to compare against a pre-defined list: |
77 |
| - |
78 |
| - - *blacklist*: input filenames matching any pattern on the list are |
79 |
| - skipped; others are deleted; |
80 |
| - |
81 |
| - - *whitelist*: input filenames matching any pattern on the list are |
82 |
| - deleted; others are skipped; |
83 |
| - |
84 |
| -- *blacklist*: blacklist file path; the first tilde `~` is translated to home |
85 |
| - dir; |
86 |
| - |
87 |
| -- *whitelist*: whitelist file path; the first tilde `~` is translated to home |
88 |
| - dir; |
89 |
| - |
90 |
| -### blacklist and whitelist |
91 |
| - |
92 |
| -blacklist and whitelist have the same format: each line specifies a pattern; the |
93 |
| -first tilde `~` in the pattern is translated to home dir; |
94 |
| - |
95 |
| -each input filename is first converted to realpath (without symlink expansion), |
96 |
| -then compared with these patterns one by one, until a match is found or no match |
97 |
| -is found; therefore, when you are writing patterns, expect them to be matched |
98 |
| -against realpaths; |
99 |
| - |
100 |
| -## depend |
101 |
| - |
102 |
| -skip-rm depends on: |
103 |
| - |
104 |
| -- [jq](https://github.com/stedolan/jq); |
105 |
| - |
106 |
| -- [sed](https://www.gnu.org/software/sed/); |
| 28 | +these implementations share the same config files; a sample config is provided |
| 29 | +in `config` dir; the entire config has a json file plus some lists of patterns; |
107 | 30 |
|
108 | 31 | ## license
|
109 | 32 |
|
110 |
| -Copyright (C) 2018 Cyker Way |
| 33 | +Copyright (C) 2018-2022 Cyker Way |
111 | 34 |
|
112 | 35 | This program is free software: you can redistribute it and/or modify it under
|
113 | 36 | the terms of the GNU General Public License as published by the Free Software
|
|
0 commit comments