|
| 1 | +# Terminal File Search |
| 2 | + |
| 3 | +A powerful command-line tool for searching files with various filters and options. |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +This Python script provides a comprehensive terminal-based file search utility that allows you to search for files based on multiple criteria including name patterns, file extensions, file types, and size ranges. It supports both recursive and non-recursive searches with detailed or simple output formats. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Name Pattern Search**: Search files using wildcard patterns (e.g., `*.txt`, `test_*`) |
| 12 | +- **Extension Filter**: Filter files by specific extensions |
| 13 | +- **Type Filter**: Search specifically for files or directories |
| 14 | +- **Size Range**: Filter by minimum and maximum file sizes |
| 15 | +- **Recursive Search**: Search through all subdirectories |
| 16 | +- **Verbose Output**: Display detailed information including file size and modification time |
| 17 | +- **Result Limiting**: Limit the number of search results |
| 18 | +- **Human-Readable Formats**: File sizes displayed in KB, MB, GB, etc. |
| 19 | + |
| 20 | +## Requirements |
| 21 | + |
| 22 | +- Python 3.6 or higher |
| 23 | +- No external dependencies (uses only standard library) |
| 24 | + |
| 25 | +## Installation |
| 26 | + |
| 27 | +1. Clone this repository or download the script |
| 28 | +2. Make the script executable (on Unix-like systems): |
| 29 | +```bash |
| 30 | +chmod +x terminal_file_search.py |
| 31 | +``` |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +### Basic Syntax |
| 36 | +```bash |
| 37 | +python terminal_file_search.py [directory] [options] |
| 38 | +``` |
| 39 | + |
| 40 | +### Options |
| 41 | + |
| 42 | +- `-n, --name PATTERN`: File name pattern (supports wildcards like `*` and `?`) |
| 43 | +- `-e, --ext EXTENSION`: File extension without dot (e.g., `py`, `txt`) |
| 44 | +- `-t, --type TYPE`: Type filter - `f` for files, `d` for directories |
| 45 | +- `--min-size SIZE`: Minimum file size in KB |
| 46 | +- `--max-size SIZE`: Maximum file size in KB |
| 47 | +- `-r, --recursive`: Search recursively through subdirectories |
| 48 | +- `-v, --verbose`: Show detailed output with file size and modification time |
| 49 | +- `-l, --limit NUMBER`: Limit the number of results |
| 50 | + |
| 51 | +### Examples |
| 52 | + |
| 53 | +#### Search for all Python files in current directory |
| 54 | +```bash |
| 55 | +python terminal_file_search.py -e py |
| 56 | +``` |
| 57 | + |
| 58 | +#### Search recursively for files starting with "test" |
| 59 | +```bash |
| 60 | +python terminal_file_search.py -n "test*" -r |
| 61 | +``` |
| 62 | + |
| 63 | +#### Find all files larger than 100KB |
| 64 | +```bash |
| 65 | +python terminal_file_search.py --min-size 100 -r |
| 66 | +``` |
| 67 | + |
| 68 | +#### Search for directories only |
| 69 | +```bash |
| 70 | +python terminal_file_search.py -t d -r |
| 71 | +``` |
| 72 | + |
| 73 | +#### Verbose search for text files with size constraints |
| 74 | +```bash |
| 75 | +python terminal_file_search.py -e txt --min-size 10 --max-size 1000 -r -v |
| 76 | +``` |
| 77 | + |
| 78 | +#### Search in specific directory with result limit |
| 79 | +```bash |
| 80 | +python terminal_file_search.py /path/to/directory -n "*.log" -r -l 10 |
| 81 | +``` |
| 82 | + |
| 83 | +#### Combine multiple filters |
| 84 | +```bash |
| 85 | +python terminal_file_search.py . -e py -n "*test*" --min-size 5 -r -v |
| 86 | +``` |
| 87 | + |
| 88 | +## Output Format |
| 89 | + |
| 90 | +### Standard Output |
| 91 | +``` |
| 92 | +/path/to/file1.py |
| 93 | +/path/to/file2.py |
| 94 | +``` |
| 95 | + |
| 96 | +### Verbose Output |
| 97 | +``` |
| 98 | +/path/to/file1.py | Size: 15.43 KB | Modified: 2025-10-12 20:30:15 |
| 99 | +/path/to/file2.py | Size: 8.21 KB | Modified: 2025-10-11 14:22:08 |
| 100 | +``` |
| 101 | + |
| 102 | +## Error Handling |
| 103 | + |
| 104 | +- Gracefully handles permission errors |
| 105 | +- Skips files/directories that cannot be accessed |
| 106 | +- Provides informative error messages |
| 107 | + |
| 108 | +## Contributing |
| 109 | + |
| 110 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 111 | + |
| 112 | +## License |
| 113 | + |
| 114 | +This project is open source and available under the MIT License. |
| 115 | + |
| 116 | +## Issue Reference |
| 117 | + |
| 118 | +This implementation resolves issue #788 - Terminal File Search |
0 commit comments