@singhaman21/cleansweep 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aman Singh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,447 @@
1
+ # cleansweep - Enhanced Delete Script
2
+
3
+ A powerful and safe command-line tool for deleting files and folders with comprehensive safety features, logging, and flexible pattern matching.
4
+
5
+ ## 📋 Table of Contents
6
+
7
+ - [Overview](#overview)
8
+ - [Features](#features)
9
+ - [Installation](#installation)
10
+ - [Usage](#usage)
11
+ - [Options](#options)
12
+ - [Examples](#examples)
13
+ - [Safety Features](#safety-features)
14
+ - [Output Formats](#output-formats)
15
+ - [Logging](#logging)
16
+ - [Best Practices](#best-practices)
17
+ - [Troubleshooting](#troubleshooting)
18
+ - [Contributing](#contributing)
19
+
20
+ ## 🎯 Overview
21
+
22
+ cleansweep is an enhanced bash script designed to safely and efficiently delete files and folders based on patterns, with multiple safety mechanisms to prevent accidental data loss. It provides features like dry-run mode, interactive confirmation, exclusion lists, depth control, and comprehensive logging.
23
+
24
+ ## ✨ Features
25
+
26
+ ### Core Capabilities
27
+
28
+ - **Pattern-Based Deletion**: Delete files and folders using glob patterns
29
+ - **Multiple Pattern Types**: Support for files, folders, and mixed types
30
+ - **Exclusion Lists**: Protect important files/folders from deletion
31
+ - **Depth Control**: Limit search depth in directory structures
32
+ - **Dry Run Mode**: Preview deletions without making changes
33
+ - **Interactive Mode**: Confirm each deletion individually
34
+ - **Preview Mode**: See what will be deleted before execution
35
+ - **Comprehensive Logging**: Track all operations with timestamps
36
+ - **Multiple Output Formats**: Plain text or JSON output
37
+ - **Force Mode**: Bypass safety checks when needed
38
+
39
+ ### Safety Features
40
+
41
+ - ✅ Dry-run mode to preview changes
42
+ - ✅ Interactive confirmation prompts
43
+ - ✅ Exclusion pattern support
44
+ - ✅ Preview before deletion
45
+ - ✅ Comprehensive error handling
46
+ - ✅ Detailed logging with timestamps
47
+ - ✅ Summary reports after execution
48
+
49
+ ## 📦 Installation
50
+
51
+ ### Prerequisites
52
+
53
+ - Bash 4.0 or higher
54
+ - Standard Unix utilities (find, rm, date)
55
+
56
+ ### Setup
57
+
58
+ 1. Clone or download the script:
59
+ ```bash
60
+ git clone <repository-url>
61
+ cd cleansweep
62
+ ```
63
+
64
+ 2. Make the script executable:
65
+ ```bash
66
+ chmod +x delete.sh
67
+ ```
68
+
69
+ 3. (Optional) Add to your PATH for global access:
70
+ ```bash
71
+ sudo ln -s $(pwd)/delete.sh /usr/local/bin/cleansweep
72
+ ```
73
+
74
+ ## 🚀 Usage
75
+
76
+ ### Basic Syntax
77
+
78
+ ```bash
79
+ ./delete.sh [OPTIONS]
80
+ ```
81
+
82
+ ### Quick Start
83
+
84
+ ```bash
85
+ # Preview what would be deleted (dry run)
86
+ ./delete.sh --files "*.tmp" --dry-run
87
+
88
+ # Delete temporary files interactively
89
+ ./delete.sh --files "*.tmp" --interactive
90
+
91
+ # Delete with logging
92
+ ./delete.sh --files "*.log" --log cleanup.log
93
+ ```
94
+
95
+ ## 📖 Options
96
+
97
+ ### Pattern Selection
98
+
99
+ | Option | Description | Example |
100
+ |--------|-------------|---------|
101
+ | `--files PATTERN` | Delete files matching pattern | `--files "*.tmp"` |
102
+ | `--folders PATTERN` | Delete folders matching pattern | `--folders "temp"` |
103
+ | `--types PATTERN` | Delete files/directories matching pattern | `--types "*.log"` |
104
+
105
+ ### Safety & Control
106
+
107
+ | Option | Description |
108
+ |--------|-------------|
109
+ | `--dry-run` | Simulate deletion without actually deleting |
110
+ | `--interactive` | Prompt for confirmation before each deletion |
111
+ | `--preview` | Display list of items to be deleted |
112
+ | `--force` | Bypass safety checks and warnings |
113
+
114
+ ### Filtering & Limits
115
+
116
+ | Option | Description | Example |
117
+ |--------|-------------|---------|
118
+ | `--exclude PATTERN` | Exclude patterns from deletion (can use multiple times) | `--exclude "important"` |
119
+ | `--depth NUMBER` | Limit search depth in directory structure | `--depth 2` |
120
+
121
+ ### Output & Logging
122
+
123
+ | Option | Description | Example |
124
+ |--------|-------------|---------|
125
+ | `--log FILE` | Generate log file with timestamps | `--log deletion.log` |
126
+ | `--format FORMAT` | Output format: `plain` or `json` | `--format json` |
127
+ | `-h, --help` | Display help message | `--help` |
128
+
129
+ ## 💡 Examples
130
+
131
+ ### Example 1: Safe Cleanup with Preview
132
+
133
+ Delete temporary files with preview and logging:
134
+
135
+ ```bash
136
+ ./delete.sh --files "*.tmp" --preview --log cleanup.log --dry-run
137
+ ```
138
+
139
+ **Output:**
140
+ ```
141
+ [2024-01-15 10:30:00] [INFO] Starting deletion operation...
142
+ [2024-01-15 10:30:00] [INFO] Preview: Items that will be deleted (5 items):
143
+ - ./cache/file1.tmp
144
+ - ./cache/file2.tmp
145
+ - ./logs/error.tmp
146
+ - ./temp/data.tmp
147
+ - ./tmp/backup.tmp
148
+ [2024-01-15 10:30:00] [INFO] Would delete: ./cache/file1.tmp
149
+ ...
150
+ ```
151
+
152
+ ### Example 2: Interactive Deletion
153
+
154
+ Delete log files with confirmation prompts:
155
+
156
+ ```bash
157
+ ./delete.sh --types "*.log" --interactive --depth 2
158
+ ```
159
+
160
+ **Interactive Prompt:**
161
+ ```
162
+ Delete './logs/app.log'? [y/N]: y
163
+ [2024-01-15 10:31:00] [INFO] Deleted file: ./logs/app.log
164
+ Delete './logs/error.log'? [y/N]: n
165
+ [2024-01-15 10:31:05] [INFO] Skipped: ./logs/error.log
166
+ ```
167
+
168
+ ### Example 3: Exclude Important Files
169
+
170
+ Delete temporary files but exclude important directories:
171
+
172
+ ```bash
173
+ ./delete.sh --files "*.tmp" --exclude "important_folder" --exclude "backup" --log cleanup.log
174
+ ```
175
+
176
+ ### Example 4: Cleanup with Depth Limit
177
+
178
+ Delete cache folders up to 2 levels deep:
179
+
180
+ ```bash
181
+ ./delete.sh --folders "cache" --depth 2 --preview
182
+ ```
183
+
184
+ ### Example 5: JSON Output Format
185
+
186
+ Get output in JSON format for programmatic processing:
187
+
188
+ ```bash
189
+ ./delete.sh --files "*.tmp" --format json --dry-run
190
+ ```
191
+
192
+ **Output:**
193
+ ```json
194
+ {"timestamp":"2024-01-15 10:32:00","level":"INFO","message":"Starting deletion operation..."}
195
+ {"timestamp":"2024-01-15 10:32:00","level":"INFO","message":"Would delete: ./file.tmp"}
196
+ {"items":[{"path":"./file.tmp"}]}
197
+ ```
198
+
199
+ ### Example 6: Complex Cleanup
200
+
201
+ Multiple patterns with exclusions and logging:
202
+
203
+ ```bash
204
+ ./delete.sh \
205
+ --files "*.tmp" \
206
+ --folders "temp" \
207
+ --exclude "important_folder" \
208
+ --exclude "backup" \
209
+ --log deletion_log.txt \
210
+ --dry-run \
211
+ --preview
212
+ ```
213
+
214
+ ### Example 7: Force Delete with Logging
215
+
216
+ Force delete without prompts (use with caution):
217
+
218
+ ```bash
219
+ ./delete.sh --folders "cache" --force --log cleanup.log
220
+ ```
221
+
222
+ ## 🛡️ Safety Features
223
+
224
+ ### Dry Run Mode
225
+
226
+ Always test your deletion patterns with `--dry-run` first:
227
+
228
+ ```bash
229
+ ./delete.sh --files "*.tmp" --dry-run
230
+ ```
231
+
232
+ This shows what would be deleted without actually deleting anything.
233
+
234
+ ### Interactive Mode
235
+
236
+ Get confirmation for each item:
237
+
238
+ ```bash
239
+ ./delete.sh --files "*.tmp" --interactive
240
+ ```
241
+
242
+ ### Preview Mode
243
+
244
+ See all items before deletion:
245
+
246
+ ```bash
247
+ ./delete.sh --files "*.tmp" --preview
248
+ ```
249
+
250
+ ### Exclusion Patterns
251
+
252
+ Protect important files and folders:
253
+
254
+ ```bash
255
+ ./delete.sh --files "*.tmp" --exclude "important" --exclude "backup"
256
+ ```
257
+
258
+ ## 📊 Output Formats
259
+
260
+ ### Plain Text (Default)
261
+
262
+ Human-readable output with timestamps and log levels:
263
+
264
+ ```
265
+ [2024-01-15 10:30:00] [INFO] Starting deletion operation...
266
+ [2024-01-15 10:30:00] [INFO] Deleted file: ./file.tmp
267
+ ```
268
+
269
+ ### JSON Format
270
+
271
+ Machine-readable output for automation:
272
+
273
+ ```json
274
+ {"timestamp":"2024-01-15 10:30:00","level":"INFO","message":"Deleted file: ./file.tmp"}
275
+ ```
276
+
277
+ ## 📝 Logging
278
+
279
+ ### Log File Format
280
+
281
+ When using `--log`, the script creates a detailed log file:
282
+
283
+ ```
284
+ ==========================================
285
+ Deletion Log - 2024-01-15 10:30:00
286
+ ==========================================
287
+ Dry Run: false
288
+ Interactive: true
289
+ Force: false
290
+ Files Pattern: *.tmp
291
+ Exclude Patterns: important backup
292
+ Max Depth: 2
293
+ ==========================================
294
+
295
+ [2024-01-15 10:30:00] [INFO] Starting deletion operation...
296
+ [2024-01-15 10:30:01] [INFO] Deleted file: ./file1.tmp
297
+ [2024-01-15 10:30:02] [INFO] Deleted file: ./file2.tmp
298
+ ```
299
+
300
+ ### Log File Benefits
301
+
302
+ - Track all deletion operations
303
+ - Audit trail for compliance
304
+ - Debugging failed deletions
305
+ - Historical record of cleanup activities
306
+
307
+ ## 🎯 Best Practices
308
+
309
+ ### 1. Always Use Dry Run First
310
+
311
+ ```bash
312
+ # Test your pattern first
313
+ ./delete.sh --files "*.tmp" --dry-run
314
+ ```
315
+
316
+ ### 2. Use Preview Mode
317
+
318
+ ```bash
319
+ # See what will be deleted
320
+ ./delete.sh --files "*.tmp" --preview
321
+ ```
322
+
323
+ ### 3. Enable Logging
324
+
325
+ ```bash
326
+ # Keep a record of deletions
327
+ ./delete.sh --files "*.tmp" --log cleanup.log
328
+ ```
329
+
330
+ ### 4. Use Exclusion Patterns
331
+
332
+ ```bash
333
+ # Protect important files
334
+ ./delete.sh --files "*.tmp" --exclude "important" --exclude "backup"
335
+ ```
336
+
337
+ ### 5. Combine Safety Features
338
+
339
+ ```bash
340
+ # Maximum safety
341
+ ./delete.sh --files "*.tmp" --dry-run --preview --interactive --log cleanup.log
342
+ ```
343
+
344
+ ### 6. Limit Search Depth
345
+
346
+ ```bash
347
+ # Avoid deep recursive searches
348
+ ./delete.sh --files "*.tmp" --depth 3
349
+ ```
350
+
351
+ ## 🔧 Troubleshooting
352
+
353
+ ### Issue: "No items found matching the specified patterns"
354
+
355
+ **Solution:**
356
+ - Verify your pattern syntax (use quotes for patterns with wildcards)
357
+ - Check if files/folders exist in the current directory
358
+ - Try using `--preview` to see what matches
359
+
360
+ ```bash
361
+ ./delete.sh --files "*.tmp" --preview
362
+ ```
363
+
364
+ ### Issue: "Permission denied"
365
+
366
+ **Solution:**
367
+ - Check file/folder permissions
368
+ - Run with appropriate user permissions
369
+ - Some system files may require sudo (use with extreme caution)
370
+
371
+ ### Issue: "Failed to delete" errors
372
+
373
+ **Solution:**
374
+ - Check if files are in use by other processes
375
+ - Verify write permissions
376
+ - Review the log file for detailed error information
377
+
378
+ ### Issue: Pattern not matching expected files
379
+
380
+ **Solution:**
381
+ - Use `--dry-run` and `--preview` to test patterns
382
+ - Remember that patterns are glob patterns, not regex
383
+ - Use quotes around patterns: `--files "*.tmp"`
384
+
385
+ ## 📋 Pattern Matching
386
+
387
+ ### Supported Patterns
388
+
389
+ - `*.tmp` - All files ending with .tmp
390
+ - `temp*` - All items starting with "temp"
391
+ - `*cache*` - All items containing "cache"
392
+ - `temp` - Exact match for "temp"
393
+
394
+ ### Pattern Examples
395
+
396
+ ```bash
397
+ # Delete all temporary files
398
+ ./delete.sh --files "*.tmp"
399
+
400
+ # Delete all log files
401
+ ./delete.sh --files "*.log"
402
+
403
+ # Delete folders named "cache"
404
+ ./delete.sh --folders "cache"
405
+
406
+ # Delete items matching multiple patterns
407
+ ./delete.sh --types "*.tmp" --types "*.log"
408
+ ```
409
+
410
+ ## 🔄 Exit Codes
411
+
412
+ - `0` - Success (all deletions completed)
413
+ - `1` - Error (failed deletions or invalid arguments)
414
+
415
+ ## 📄 Summary Report
416
+
417
+ After execution, the script provides a summary:
418
+
419
+ ```
420
+ === Deletion Summary ===
421
+ Total items found: 10
422
+ Items successfully deleted: 8
423
+ Failed deletions: 2
424
+ - ./protected/file.tmp
425
+ - ./locked/data.tmp
426
+ ```
427
+
428
+ ## 🤝 Contributing
429
+
430
+ Contributions are welcome! Please feel free to submit issues or pull requests.
431
+
432
+ ## ⚠️ Warning
433
+
434
+ **Always use `--dry-run` and `--preview` before performing actual deletions. This script permanently deletes files and folders. Use with caution!**
435
+
436
+ ## 📜 License
437
+
438
+ This script is provided as-is for educational and practical use. Use at your own risk.
439
+
440
+ ## 🙏 Acknowledgments
441
+
442
+ Created as an enhanced deletion tool with safety features and comprehensive logging capabilities.
443
+
444
+ ---
445
+
446
+ **Remember:** When in doubt, use `--dry-run` first! 🛡️
447
+
package/USAGE.md ADDED
@@ -0,0 +1,81 @@
1
+ # cleansweep Usage Guide
2
+
3
+ ## Installation
4
+
5
+ ### Using npx (Recommended - No Installation Required)
6
+
7
+ ```bash
8
+ npx cleansweep --files "*.tmp" --dry-run
9
+ ```
10
+
11
+ ### Local Installation
12
+
13
+ ```bash
14
+ npm install
15
+ npm run build
16
+ npm start -- --files "*.tmp" --dry-run
17
+ ```
18
+
19
+ ### Global Installation
20
+
21
+ ```bash
22
+ npm install -g .
23
+ cleansweep --files "*.tmp" --dry-run
24
+ ```
25
+
26
+ ## Quick Examples
27
+
28
+ ### Dry Run (Safe Testing)
29
+ ```bash
30
+ npx cleansweep --files "*.tmp" --dry-run
31
+ ```
32
+
33
+ ### Preview Before Deletion
34
+ ```bash
35
+ npx cleansweep --files "*.tmp" --preview
36
+ ```
37
+
38
+ ### Interactive Deletion
39
+ ```bash
40
+ npx cleansweep --files "*.log" --interactive
41
+ ```
42
+
43
+ ### Delete with Logging
44
+ ```bash
45
+ npx cleansweep --files "*.tmp" --log cleanup.log
46
+ ```
47
+
48
+ ### Multiple Patterns with Exclusions
49
+ ```bash
50
+ npx cleansweep --files "*.tmp" --folders "temp" --exclude "important" --exclude "backup" --dry-run
51
+ ```
52
+
53
+ ### Limited Depth Search
54
+ ```bash
55
+ npx cleansweep --folders "cache" --depth 2 --preview
56
+ ```
57
+
58
+ ### JSON Output Format
59
+ ```bash
60
+ npx cleansweep --files "*.tmp" --format json --dry-run
61
+ ```
62
+
63
+ ## Development
64
+
65
+ ### Build TypeScript
66
+ ```bash
67
+ npm run build
68
+ ```
69
+
70
+ ### Run in Development Mode
71
+ ```bash
72
+ npm run dev -- --files "*.tmp" --dry-run
73
+ ```
74
+
75
+ ## Notes
76
+
77
+ - Always use `--dry-run` first to test your patterns
78
+ - Use `--preview` to see what will be deleted
79
+ - Combine `--dry-run` and `--preview` for maximum safety
80
+ - The TypeScript version provides the same functionality as the bash script
81
+