{"id":40852741,"url":"https://github.com/kenchou/file-clean-rust","last_synced_at":"2026-01-21T23:42:02.139Z","repository":{"id":204070320,"uuid":"693134232","full_name":"kenchou/file-clean-rust","owner":"kenchou","description":"Batch clean filenames and delete junk files based on configured rules. 基于配置的规则，批量清理文件名，删除匹配的垃圾文件。","archived":false,"fork":false,"pushed_at":"2025-12-03T12:56:21.000Z","size":115,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-06T16:18:05.912Z","etag":null,"topics":["cli","filesystem","rust","utility"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kenchou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-09-18T12:21:27.000Z","updated_at":"2025-12-03T12:56:25.000Z","dependencies_parsed_at":"2023-11-03T06:27:18.473Z","dependency_job_id":"8e50140c-30bc-4663-b6e2-1350ed6ebf0f","html_url":"https://github.com/kenchou/file-clean-rust","commit_stats":null,"previous_names":["kenchou/file-clean-rust"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/kenchou/file-clean-rust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenchou%2Ffile-clean-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenchou%2Ffile-clean-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenchou%2Ffile-clean-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenchou%2Ffile-clean-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kenchou","download_url":"https://codeload.github.com/kenchou/file-clean-rust/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenchou%2Ffile-clean-rust/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28646953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T21:29:11.980Z","status":"ssl_error","status_checked_at":"2026-01-21T21:24:31.872Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","filesystem","rust","utility"],"created_at":"2026-01-21T23:42:02.050Z","updated_at":"2026-01-21T23:42:02.130Z","avatar_url":"https://github.com/kenchou.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# file-clean-rust\n\nClean up (rename/delete) folders and files according to configured rules.\n\n## Motivation\n\nResources downloaded through P2P networks usually contain a lot of junk files or padding files.  \nSome clients (such as xunlei) have automatic cleaning features, but `aria2` lacks this functionality.  \nTherefore, I wrote a tool to clean up directories and files.\n\n## Usage\n\n```text\nUsage: file-clean-rust [OPTIONS] [path]\n\nArguments:\n  [path]  target path to clean up\n\nOptions:\n  -c, --config \u003cFILE\u003e        Sets a custom config file\n  -d, --delete               Match filename deletion rule. [default]\n  -D, --no-delete            Do not match filename deletion rule.\n  -x, --hash                 Match hash deletion rule. [default]\n  -X, --no-hash              Do not match hash deletion rule.\n  -r, --rename               Match file renaming rule. [default]\n  -R, --no-rename            Do not match file renaming rule.\n  -t, --skip-tmp             Skip the .tmp directory. [default]\n  -T, --no-skip-tmp          Do not skip the .tmp directory.\n  -e, --remove-empty-dir     Delete empty directories. [default]\n  -E, --no-remove-empty-dir  Do not delete empty directories.\n      --prune                Perform the prune action.\n  -v, --verbose...           Verbose mode.\n  -h, --help                 Print help\n  -V, --version              Print version\n```\n\nexample:  \n`file-clean-rust ~/Downloads` dry-run and see result  \n`file-clean-rust ~/Downloads --prune` prune the target path and see result\n\n## File Cleanup Configuration\n\nThe default configuration file `.cleanup-patterns.yml` is searched for starting from the specified target path,  \nmoving upwards step by step until the root directory is reached.  \nIf it is not found, it will then be looked for in the user's home directory.\n\n```yaml\nremove: |-\n  # Any line that starts with '#' is treated as a comment. # 任何以井号 '#' 开头的行都做为注释\n  # Match the filename exactly. # 匹配精确的文件名\n  example_filename.ext\n  # '*' and '?' are wildcards.  # 可以使用通配符\n  wildcard*\n  # For more complex matching, use regular expressions. # 更复杂的匹配规则可以使用正则表达式\n  # Notice: regex must start with \"/\".                  # 注意：正则表达式必需以斜杠 '/' 开头. (区别于通配符规则)\n  /regex_pattern1\n  /regex_pattern2\nremove_hash:\n  # Sometimes, files may have the same content but different names. # 有时候一些文件具有相同的内容，但是会有不同的名字；\n  # Or they may have very common names (e.g., 01.jpg).              # 或者具有很常用的名字（比如 01.jpg），\n  # You can use hash matching to delete them.                       # 可以使用哈希匹配来删除。\n  # To improve efficiency, this method first matches the file names # 为了提升效率，此方法先匹配文件名，\n  # and then calculates the hash values.                            # 再计算哈希值。\n  # Only if both match will the file be deleted.                    # 二者都匹配才会删除。\n  # The file name rules are the same as the `remove` rules          # 文件名规则同 `remove` 规则，\n  # and support wildcards and regular expressions.                  # 支持通配符和正则表达式。\n  # Note: It is not recommended to use wildcards like *.jpg,        # 注：不建议使用 *.jpg 这样的通配符，\n  # as this may result in too many files needing hash calculation.  #    可能导致需要计算 hash 的文件过多。\n  \"filename_or_wildcard\":\n    - md5hash1\n    - md5hash2\n  \"/file1|file2\":\n    - md5hash1\n    - md5hash2\ncleanup: |-\n  # The filename cleaning rules only support regular expressions, # 文件名清理（改名）只支持正则表达式 \n  # so there is no need to start with '/'.                        # 所以不需要使用斜杠 '/' 开头 \n  # The matched strings will be replaced with an empty string.    # 匹配的内容会被替换成空串\n  regex_pattern1\n  regex_pattern2\n```\n\n## Directory Monitoring\n\nThe `monitor-dir.sh` script provides real-time monitoring of directories for newly moved folders.  \nWhen a directory is moved into the monitored path, it automatically runs `file-clean-rust` to clean it up.\n\n### Features\n\n- **Cross-platform support**: Works on Linux (using `inotifywait`) and macOS (using `fswatch`)\n- **Smart waiting mechanism**: Waits for directory to stabilize before processing to ensure all files are moved\n- **Safe path handling**: Correctly handles filenames with spaces and special characters\n- **Timeout protection**: Maximum wait time to prevent infinite waiting\n\n### Prerequisites\n\n**Linux/Unix systems:**\n\n```bash\n# Ubuntu/Debian\nsudo apt-get install inotify-tools\n\n# RHEL/CentOS/Fedora\nsudo yum install inotify-tools\n# or\nsudo dnf install inotify-tools\n```\n\n**macOS:**\n\n```bash\nbrew install fswatch\n```\n\n### Script Usage\n\n```bash\n# Monitor a single directory\n./monitor-dir.sh /data/Downloads/TV/\n\n# Monitor multiple directories\n./monitor-dir.sh /data/Downloads/TV/ /data/Downloads/Movies/\n```\n\n### Script Configuration\n\nThe script uses the following default settings:\n\n- **Maximum wait time**: 60 seconds\n- **Stability check time**: 3 seconds (waits for 3 seconds of no file activity)\n\nYou can modify these values in the `wait_for_directory_stable()` function:\n\n```bash\nlocal max_wait=60     # Maximum wait time (seconds)\nlocal stable_time=3   # Stability time (seconds)\n```\n\n### How it works\n\n1. Monitors specified directories for `moved_to` events\n2. When a directory is moved in, starts monitoring that directory for file changes\n3. Waits until no file activity is detected for the stability period\n4. Runs `file-clean-rust --prune` on the stabilized directory\n5. Continues monitoring for new directory movements\n\n### Example Output\n\n```text\n使用文件监控工具: fswatch\n检测到目录移动事件: /data/Downloads/TV/MyShow.S01.2025/Episode.01.1080p.WEB-DL\n事件类型: MOVED_TO,ISDIR\n等待目录稳定: /data/Downloads/TV/MyShow.S01.2025/Episode.01.1080p.WEB-DL\n检测到文件变化，继续等待...\n检测到文件变化，继续等待...\n目录已稳定 3 秒，开始处理\n开始处理目录: /data/Downloads/TV/MyShow.S01.2025/Episode.01.1080p.WEB-DL\n正在扫描文件...\n[... file-clean-rust output ...]\n```\n\n## Related projects\n\n- [aria2](https://github.com/aria2/aria2)\n- [aria2rpc-oversee](https://github.com/kenchou/aria2rpc-oversee)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenchou%2Ffile-clean-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkenchou%2Ffile-clean-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenchou%2Ffile-clean-rust/lists"}