{"id":13564645,"url":"https://github.com/shenwei356/brename","last_synced_at":"2025-10-21T04:43:02.713Z","repository":{"id":10465146,"uuid":"12638802","full_name":"shenwei356/brename","owner":"shenwei356","description":"A practical cross-platform command-line tool for safely batch renaming files/directories via regular expression","archived":false,"fork":false,"pushed_at":"2024-11-22T10:54:21.000Z","size":14814,"stargazers_count":263,"open_issues_count":7,"forks_count":22,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-22T11:30:24.330Z","etag":null,"topics":["batch","batch-rename","batch-rename-files","batch-renamer","go","golang","rename","safe","windows"],"latest_commit_sha":null,"homepage":"https://github.com/shenwei356/brename","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shenwei356.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"custom":"http://paypal.me/shenwei356"}},"created_at":"2013-09-06T07:48:12.000Z","updated_at":"2024-11-22T10:54:25.000Z","dependencies_parsed_at":"2023-09-25T04:57:06.933Z","dependency_job_id":"f019142e-6a99-41cd-a689-de9e57ccc82c","html_url":"https://github.com/shenwei356/brename","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenwei356%2Fbrename","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenwei356%2Fbrename/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenwei356%2Fbrename/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenwei356%2Fbrename/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shenwei356","download_url":"https://codeload.github.com/shenwei356/brename/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247083201,"owners_count":20880794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["batch","batch-rename","batch-rename-files","batch-renamer","go","golang","rename","safe","windows"],"created_at":"2024-08-01T13:01:34.001Z","updated_at":"2025-10-21T04:43:02.704Z","avatar_url":"https://github.com/shenwei356.png","language":"Go","funding_links":["http://paypal.me/shenwei356"],"categories":["Go","Command Line Tools","Ranked by starred repositories"],"sub_categories":[],"readme":"# brename: batch renaming safely\n\n[![Built with GoLang](https://img.shields.io/badge/powered_by-go-6362c2.svg?style=flat)](https://golang.org)\n[![Go Report Card](https://goreportcard.com/badge/github.com/shenwei356/brename)](https://goreportcard.com/report/github.com/shenwei356/brename)\n[![Cross-platform](https://img.shields.io/badge/platform-any-ec2eb4.svg?style=flat)](#download)\n[![Latest Version](https://img.shields.io/github/release/shenwei356/brename.svg?style=flat?maxAge=86400)](https://github.com/shenwei356/brename/releases)\n[![Github Releases](https://img.shields.io/github/downloads/shenwei356/brename/latest/total.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases)\n\n`brename` is a cross-platform command-line tool for safely batch renaming files/directories via regular expression.\n\n\u003cimg src=\"screenshot/success.png\" width=\"700\"/\u003e\n\n## Table of Contents\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Examples](#examples)\n- [Real-world examples](#real-world-examples)\n- [FAQS](#faqs)\n- [Contact](#contact)\n- [License](#license)\n- [Starchart](#starchart)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Features\n\n- **Cross-platform**. Supporting Windows, Mac OS X and Linux, \n    - Windows file systems, including NTFS and FAT, are case-insensitive.\n    Some operations are allowed on Linux, while they could be dangerous on Windows.\n    [For example](https://github.com/shenwei356/brename/issues/28), renaming `test.tar.gz` to `test.tar` will overwrite `TEST.tar`. \n    `brename` (v2.13.0 and later versions) can handle these cases appropriately (`-w` and `-W`).\n\n- **Safe**. ***It helps you check potential conflicts and errors before it's too late***.\n\n    \u003cimg src=\"screenshot/check-error.png\" width=\"700\"/\u003e\n\n    Some common conflict and errors that might happen with commands like `mv` or `rename`.\n\n    - `New path existed`: **Existed files might be overwritten, causing data loss**.\n\t- `Overwriting newly renamed path`. **Existed files might be overwritten, causing data loss.**\n       This case is hard to check by eyes.\n\t- `Missing target`: New file is empty, that's not allowed.\n\t- `New path ending with a space`: Not allowed in Windows. It's legal in Linux, but might cause unexpected errors.\n\t- `New path ending with a period`: Not allowed in Windows.\n\n- **Supporting dry run**. A good habbit.\n\n    \u003cimg src=\"screenshot/dry-run.png\" width=\"700\"/\u003e\n\n- **Supporting Undo** the LAST successful operation, like a time machine.\n\n    \u003cimg src=\"screenshot/undo.png\" width=\"700\"/\u003e\n\n- **Overwrite can be detected and users can choose whether overwrite or leave it** (`-o/--overwrite-mode`).\n- **File filtering**.\n    - Supporting including (`-f/--include-filters`) and excluding (`-F/--exclude-filters`) files via regular expression.\n    - No need to run commands like `find ./ -name \"*.html\" -exec CMD`.\n- **Renaming submatch with corresponding value via key-value file** (`-r \"{kv}\" -k kv.tsv`).\n- **Renaming via ascending integer** (`-r \"{nr}\"`). \n- **Automatically making directoy**: e.g., renaming `a-b-c.txt` to `a/b/c.txt`.\n- **Recursively renaming both files and directories** (`-R/--recursive`, `-D/--including-dir`, `--only-dir`).\n\n\n\n## Installation\n\n`brename` is implemented in [Go](https://golang.org/) programming language,\n executable binary files **for most popular operating systems** are freely available\n  in [release](https://github.com/shenwei356/brename/releases) page.\n\n#### Method 0: Conda\n\n[Install conda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html), then run\n\n    conda install -c conda-forge brename\n\nOr use [mamba](https://mamba.readthedocs.io/en/latest/installation/mamba-installation.html), which is faster.\n\n    mamba install -c conda-forge brename\n\n#### Method 1: Download binaries\n\n[brename v2.14.0](https://github.com/shenwei356/brename/releases/tag/v2.14.0)\n[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/brename/v2.14.0/total.svg)](https://github.com/shenwei356/brename/releases/tag/v2.14.0)\n\n***Tip: run `brename -V` to check update !!!***\n\nOS     |Arch      |File, 中国镜像                                                                                                                                                                              |Download Count\n:------|:---------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\nLinux  |32-bit    |[brename_linux_386.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_linux_386.tar.gz),\u003cbr/\u003e [中国镜像](http://app.shenwei.me/data/brename/brename_linux_386.tar.gz)                            |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_linux_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_linux_386.tar.gz)\nLinux  |**64-bit**|[**brename_linux_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_linux_amd64.tar.gz),\u003cbr/\u003e [中国镜像](http://app.shenwei.me/data/brename/brename_linux_amd64.tar.gz)                  |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_linux_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_linux_amd64.tar.gz)\nLinux  |arm64     |[**brename_linux_arm64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_linux_arm64.tar.gz),\u003cbr/\u003e [中国镜像](http://app.shenwei.me/data/brename/brename_linux_arm64.tar.gz)                  |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_linux_arm64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_linux_arm64.tar.gz)\nOS X   |**64-bit**|[**brename_darwin_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_darwin_amd64.tar.gz),\u003cbr/\u003e [中国镜像](http://app.shenwei.me/data/brename/brename_darwin_amd64.tar.gz)               |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_darwin_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_darwin_amd64.tar.gz)\nOS X   |arm64     |[**brename_darwin_arm64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_darwin_arm64.tar.gz),\u003cbr/\u003e [中国镜像](http://app.shenwei.me/data/brename/brename_darwin_arm64.tar.gz)               |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_darwin_arm64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_darwin_arm64.tar.gz)\nWindows|32-bit    |[brename_windows_386.exe.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_windows_386.exe.tar.gz),\u003cbr/\u003e [中国镜像](http://app.shenwei.me/data/brename/brename_windows_386.exe.tar.gz)          |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_windows_386.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_windows_386.exe.tar.gz)\nWindows|**64-bit**|[**brename_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_windows_amd64.exe.tar.gz),\u003cbr/\u003e [中国镜像](http://app.shenwei.me/data/brename/brename_windows_amd64.exe.tar.gz)|[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_windows_amd64.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.14.0/brename_windows_amd64.exe.tar.gz)\n\n\nJust [download](https://github.com/shenwei356/brename/releases) compressed\nexecutable file of your operating system,\nand decompress it with `tar -zxvf *.tar.gz` command or other tools.\nAnd then:\n\n1. **For Linux-like systems**\n    1. If you have root privilege simply copy it to `/usr/local/bin`:\n\n            sudo cp brename /usr/local/bin/\n\n    1. Or copy to anywhere in the environment variable `PATH`:\n\n            mkdir -p $HOME/bin/; cp brename $HOME/bin/\n\n1. **For windows**, just copy `brename.exe` to `C:\\WINDOWS\\system32`.\n\n#### Method 2: Homebrew\n\n    brew install brename\n\n#### Method 3: For ArchLinux AUR users\n\n    yaourt -S brename\n\n#### Method 4: For Scoop users\n\n    scoop install brename\n    \n#### Method 5: Compiling from source\n\n    # download Go from https://go.dev/dl\n    wget https://go.dev/dl/go1.24.2.linux-amd64.tar.gz\n    \n    tar -zxf go1.24.2.linux-amd64.tar.gz -C $HOME/\n    \n    # or \n    #   echo \"export PATH=$PATH:$HOME/go/bin\" \u003e\u003e ~/.bashrc\n    #   source ~/.bashrc\n    export PATH=$PATH:$HOME/go/bin\n    \n    git clone https://github.com/shenwei356/brename\n    cd brename\n    \n    go build\n    \n    # or statically-linked binary\n    CGO_ENABLED=0 go build -tags netgo -ldflags '-w -s'\n    \n    # or cross compile for other operating systems and architectures\n    CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build -tags netgo -ldflags '-w -s'\n\n## Usage\n\n```\n\nbrename: a practical cross-platform command-line tool for safely batch renaming files/directories via regular expression\n\nVersion: 2.14.0\n\nAuthor: Wei Shen \u003cshenwei356@gmail.com\u003e\n\nHomepage: https://github.com/shenwei356/brename\n\nWarnings:\n  1. The path in file systems like FAT32 or NTFS is case-insensitive, so you should switch on the flag\n     -w/--case-insensitive-path to correctly check file overwrites.\n  2. The flag -w/--case-insensitive-path is switched on by default on Windows, please use\n     -W/--case-sensitive-path to disable it if the file system is indeed case-sensitive.\n  3. New paths ending with periods of spaces, being error-prone, are not allowed.\n\nThree path filters:\n\n  1. -S/--skip-filters       black list     default value: ^\\. (skipping paths starting with \".\")\n  2. -F/--exclude-filters    black list     no default value\n  3. -f/--include-filters    white list     default value: .   (anything)\n\n  Notes:\n  1. Paths starting with \".\" are ignored by default, disable this with -S \"\".\n  2. These options support multiple values, e.g., -f \".html\" -f \".htm\".\n     But ATTENTION: each comma in filters is treated as a separator of multiple filters.\n     Please use double quotation marks for patterns containing comma, e.g., -p '\"A{2,}\"'\n  3. The three filters are performed in order of -S, -F, -f.\n  4. -F/--exclude-filters is prefered for excluding path, cause it has no default value.\n     Setting -S/--skip-filters will overwrite its default value.\n\n\nSpecial replacement symbols:\n\n  {nr}    Ascending integer\n  {kv}    Corresponding value of the key (captured variable $n) by key-value file,\n          n can be specified by flag -I/--key-capt-idx (default: 1)\n\nSpecial cases of replacement string:\n *1. Capture variables should be in the format of '${1}' to reduce errors.\n    a). If the capture variable is followed with space or other simple, it's OK:\n            -r '$1 abc'\n    b). If followed by numbers, characters, or underscore. That is ambiguous:\n            -r '$1abc' actually refers to the variable '1abc', please use '${1}abc'.\n            -r '$2_$1' actually refers to the variable '2_', please use '${2}_${1}'.\n  2. Want to replace with a character '$',\n    a). If using '{kv}', you need use '$$$$' instead of a single '$':\n            -r '{kv}' -k \u003c(sed 's/\\$/$$$$/' kv.txt)\n    b). If not, use '$$'. e.g., adding '$' to all numbers:\n            -p '(\\d+)' -d -r '$$${1}'\n\nUsage:\n  brename [flags]\n\nExamples:\n  1. dry run and showing potential dangerous operations (-d)\n      brename -p \"abc\" -d\n  2. dry run and only show operations that will cause error (-v)\n      brename -p \"abc\" -d -v 2\n  3. only renaming specific paths via include filters (-f)\n      brename -p \":\" -r \"-\" -f \".htm$\" -f \".html$\"\n  4. renaming all .jpeg files to .jpg in all subdirectories (-R)\n      brename -p \"\\.jpeg\" -r \".jpg\" -R   dir\n  5. using capture variables, e.g., $1, $2 ...\n      brename -p \"(a)\" -r \"\\$1\\$1\"\n      or brename -p \"(a)\" -r '$1$1' in Linux/Mac OS X\n  6. renaming directory too (-D)\n      brename -p \":\" -r \"-\" -R -D   pdf-dirs\n  7. using key-value file (-k)\n      brename -p \"(.+)\" -r \"{kv}\" -k kv.tsv\n  8. do not touch file extension (-e)\n      brename -p \".+\" -r \"{nr}\" -f .mkv -f .mp4 -e\n  9. only list paths that match pattern (-l)\n      brename -i -f '.docx?$' -p . -R -l\n  10. undo the LAST successful operation (-u)\n      brename -u\n  11. disable undo if you do not want to create .brename_detail.txt (-x)\n      brename -p xxx -r yyy -x\n  12. clear/remove all .brename_detail.txt files (--clear)\n      brename --clear -R\n  13. also operate on hidden files: empty -S (default: ^\\.)\n      brename -p xxx -r yyy -S \"\"\n\n  More examples: https://github.com/shenwei356/brename\n\nFlags:\n  -w, --case-insensitive-path     the file system (e.g., FAT32 or NTFS) is case-insensitive. It's\n                                  automatically swiched on on Windows\n  -W, --case-sensitive-path       believing that the file system is case-sensitive. Please use this to\n                                  disable the flag -w/--case-insensitive-path, which is switched on by\n                                  default on Windows\n      --clear                     remove all .brename_detail.txt\" file, you may need to add\n                                  -R/--recursive to recursively clear all files in the given path\n  -x, --disable-undo              do not create .brename_detail.txt file for undo\n  -d, --dry-run                   print rename operations but do not run\n  -F, --exclude-filters strings   exclude file filter(s) (regular expression, NOT wildcard). multiple\n                                  values supported, e.g., -F \".html\" -F \".htm\", but ATTENTION: each\n                                  comma in the filter is treated as the separator of multiple filters,\n                                  please use double quotation marks for patterns containing comma, e.g.,\n                                  -p '\"A{2,}\"'\n  -U, --force-undo                continue undo even when some operations failed\n  -h, --help                      help for brename\n  -i, --ignore-case               ignore case of -p/--pattern, -f/--include-filters and -F/--exclude-filters\n  -E, --ignore-err                ignore director reading errors\n  -e, --ignore-ext                ignore file extension. i.e., replacement does not change file extension\n  -f, --include-filters strings   include file filter(s) (regular expression, NOT wildcard). multiple\n                                  values supported, e.g., -f \".html\" -f \".htm\", but ATTENTION: each\n                                  comma in the filter is treated as the separator of multiple filters,\n                                  please use double quotation marks for patterns containing comma, e.g.,\n                                  -p '\"A{2,}\"' (default [.])\n  -D, --including-dir             rename directories\n  -K, --keep-key                  keep the key as value when no value found for the key\n  -I, --key-capt-idx int          capture variable index of key (1-based) (default 1)\n  -m, --key-miss-repl string      replacement for key with no corresponding value\n  -k, --kv-file string            tab-delimited key-value file for replacing key with value when using\n                                  \"{kv}\" in -r (--replacement)\n  -l, --list                      only list paths that match pattern\n  -a, --list-abs                  list absolute path, using along with -l/--list\n  -s, --list-sep string           separator for list of found paths (default \"\\n\")\n      --max-depth int             maximum depth for recursive search (0 for no limit)\n  -N, --nature-sort               list paths in nature sort, using along with -l/--list\n      --nr-width int              minimum width for {nr} in flag -r/--replacement. e.g., formating \"1\"\n                                  to \"001\" by --nr-width 3 (default 1)\n      --only-dir                  only rename directories\n  -o, --overwrite-mode int        overwrite mode (0 for reporting error, 1 for overwrite, 2 for not\n                                  renaming) (default 0)\n  -p, --pattern string            search pattern (regular expression)\n  -q, --quiet                     be quiet, do not show any information and warning\n  -R, --recursive                 rename recursively\n  -r, --replacement string        replacement. capture variables supported.  e.g. $1 or ${1} (prefered)\n                                  represents the first submatch. ATTENTION: for *nix OS, use SINGLE\n                                  quote NOT double quotes or use the \\ escape character. Ascending\n                                  integer is also supported by \"{nr}\"\n  -S, --skip-filters strings      skip file filter(s) (regular expression, NOT wildcard). multiple\n                                  values supported, e.g., -S \"^\\.\" for skipping files starting with a\n                                  dot, but ATTENTION: each comma in the filter is treated as the\n                                  separator of multiple filters, please use double quotation marks for\n                                  patterns containing comma, e.g., -p '\"A{2,}\"' (default [^\\.])\n  -n, --start-num int             starting number when using {nr} in replacement (default 1)\n  -u, --undo                      undo the LAST successful operation\n  -v, --verbose int               verbose level (0 for all, 1 for warning, error and renamed files, 2\n                                  for only error and renamed files) (default 2)\n  -V, --version                   print version information and check for update\n\n```\n\n\n## Examples\n\nTake a directory for example (run `generate-example-folder.sh` to generate)\n\n    $ sh generate-example-folder.sh \n    example\n    ├── abc\n    │   ├── A.JPEG\n    │   ├── B.HTM\n    │   └── B.JPEG\n    ├── a.html\n    ├── a.jpeg\n    └── b.jpeg\n\n    # examples below were executed in directory: example\n    cd example/\n\n\n1. Recursively renaming all `.jpeg` files to `.jpg` in all subdirectories (`-R/--recursive`).\n A dry run is firstly performed for safety checking (`-d/--dry-run`).\n\n        $ brename -p \"\\.jpeg\" -r \".jpg\" -R -d\n        Searching for paths to rename...\n\n          [OK] example/a.jpeg -\u003e example/a.jpg\n          [OK] example/b.jpeg -\u003e example/b.jpg\n\n        2 path(s) to be renamed\n\n\n        $ brename -p \"\\.jpeg\" -r \".jpg\" -R\n        Searching for paths to rename...\n\n          Done searching.\n\n        Renaming paths...\n\n          [DONE] example/a.jpeg -\u003e example/a.jpg\n          [DONE] example/b.jpeg -\u003e example/b.jpg\n\n        2 path(s) renamed in 0.001 seconds\n\n        $ tree\n        .\n        ├── abc\n        │   ├── A.JPEG\n        │   ├── B.HTM\n        │   └── B.JPEG\n        ├── a.html\n        ├── a.jpg\n        └── b.jpg\n\n\n1. **Undo** the LAST successful operation, yes it's COOL! (`-u/--undo`, `-U/--force-undo`)\n    \n        $ brename -u\n        Renaming paths back...\n\n          [DONE] example/b.jpg -\u003e example/b.jpeg\n          [DONE] example/a.jpg -\u003e example/a.jpeg\n\n        2 path(s) renamed back in 0.000 seconds\n        \n   Disable undo if you do not want to create `.brename_detail.txt` (`-x`)\n   \n        $ brename -p xxx -r yyy -x\n        \n   Clear/remove all .brename_detail.txt files (`--clear`)\n  \n        $ brename --clear -R\n    \n1. Dry run, only showing operations that will cause error (just remove `-d`).\n\n        # default value of -v is 0\n        $ brename -p a -r b -R -D -d\n        Searching for paths to rename...\n\n          [OK] a.html -\u003e b.html\n          [new path existed] a.jpeg -\u003e b.jpeg\n          [OK] abc -\u003e bbc\n\n        1 potential error(s) detected, please check\n\n        $ brename -p a -r b -R -D\n        Searching for paths to rename...\n\n          Done searching.\n          [new path existed] example/a.jpeg -\u003e example/b.jpeg\n\n        1 potential error(s) detected, please check\n\n1. Ignoring cases (`-i/--ignore-case`)\n\n        $ brename -p \"\\.jpeg\" -r \".jpg\" -R -i\n        Searching for paths to rename...\n\n          Done searching.\n\n        Renaming paths...\n\n          [DONE] abc/A.JPEG -\u003e abc/A.jpg\n          [DONE] abc/B.JPEG -\u003e abc/B.jpg\n\n        2 path(s) renamed in 0.000 seconds\n\n\n        $ tree\n        .\n        ├── abc\n        │   ├── A.jpg\n        │   ├── B.HTM\n        │   └── B.jpg\n        ├── a.html\n        ├── a.jpg\n        └── b.jpg\n\n1. Using capture variables, e.g., $1, $2 ...\n\n        # or brename -p \"(a)\" -r '$1$1' in Linux/Mac OS X\n        $ brename -p \"(a)\" -r \"\\$1\\$1\" -i\n        Searching for paths to rename...\n\n          Done searching.\n\n        Renaming paths...\n\n          [DONE] a.html -\u003e aa.html\n          [DONE] a.jpg -\u003e aa.jpg\n\n        2 path(s) renamed in 0.000 seconds\n\n        $ tree\n        .\n        ├── aa.html\n        ├── aa.jpg\n        ├── abc\n        │   ├── A.jpg\n        │   ├── B.HTM\n        │   └── B.jpg\n        └── b.jpg\n\n1. Renaming directory too (`-D/--including-dir`), even renaming directory only (`-D --only-dir`)\n\n        $ brename -p \"a\" -r \"A\" -R -D\n        Searching for paths to rename...\n\n          Done searching.\n\n        Renaming paths...\n\n          [DONE] aa.html -\u003e AA.html\n          [DONE] aa.jpg -\u003e AA.jpg\n          [DONE] abc -\u003e Abc\n\n        3 path(s) renamed in 0.001 seconds\n\n        $ tree\n        .\n        ├── AA.html\n        ├── AA.jpg\n        ├── Abc\n        │   ├── A.jpg\n        │   ├── B.HTM\n        │   └── B.jpg\n        └── b.jpg\n\n\n1. **Only renaming specific files via include filters (regular expression) (`-f/--include-filters`)**\n\n        $ brename -p '(.)' -r ' $1' -d\n        Searching for paths to rename...\n\n          [OK] AA.html -\u003e  A A . h t m l\n          [OK] AA.jpg -\u003e  A A . j p g\n          [OK] b.jpg -\u003e  b . j p g\n\n        3 path(s) to be renamed\n\n\n        \n        $ brename -p '(.)' -r ' $1' -d -f '\\.jpg$'\n        Searching for paths to rename...\n\n          [OK] AA.jpg -\u003e  A A . j p g\n          [OK] b.jpg -\u003e  b . j p g\n\n        2 path(s) to be renamed\n\n\n    ***Attention: value of `-f/--include-filters` and `-F/--exclude-filters` should be regular expression, NOT wildcard!***\n        \n        $ brename -p '(.)' -r '$1 ' -d -f *.jpg\n        Seems you are using wildcard for -f/--include-filters? Make sure using regular expression: AA.jpg\n        Searching for paths to rename...\n\n\n        0 path(s) to be renamed\n        \n        $ brename -p '(.)' -r '$1 ' -d -f '*.jpg'\n        Are you using wildcard for -f/--include-filters? It should be regular expression: *.jpg\n        illegal regular expression for include filter: *.jpg\n        \n        $ brename -p '(.)' -r '$1 ' -d -f A*\n        Seems you are using wildcard for -f/--include-filters? Make sure using regular expression: AA.html\n        Searching for paths to rename...\n\n\n        0 path(s) to be renamed\n\n1. Excluding files via exclude filters (regular expression) (`-F/--exclude-filters`)\n\n        $ brename -p '(.)' -r ' $1' -d\n        Searching for paths to rename...\n\n          [OK] AA.html -\u003e  A A . h t m l\n          [OK] AA.jpg -\u003e  A A . j p g\n          [OK] b.jpg -\u003e  b . j p g\n\n        3 path(s) to be renamed\n\n\n        $ brename -p '(.)' -r ' $1' -d -F '\\.html$'\n        Searching for paths to rename...\n\n          [OK] AA.jpg -\u003e  A A . j p g\n          [OK] b.jpg -\u003e  b . j p g\n\n        2 path(s) to be renamed\n        \n1. Skipping files via skip filter (regular expression) (`-S/--skip-filters`). This filter step is performed before the exclude filters.\n  The default value `^\\.` is for skipping files starting with dot, which are hidden configuration files in Linux.\n  If you do not want to skip these paths, just empty it.\n  \n        $ brename -p xxx -r yyy -S \"\"\n\n\n1. Do not touch file extension (`-e/--ignore-ext`)\n\n        $ brename -p '(.)' -r ' $1' -d\n        Searching for paths to rename...\n\n          [OK] AA.html -\u003e  A A . h t m l\n          [OK] AA.jpg -\u003e  A A . j p g\n          [OK] b.jpg -\u003e  b . j p g\n\n        3 path(s) to be renamed\n\n        $ brename -p '(.)' -r ' $1' -d -e\n        Searching for paths to rename...\n\n          [OK] AA.html -\u003e  A A.html\n          [OK] AA.jpg -\u003e  A A.jpg\n          [OK] b.jpg -\u003e  b.jpg\n\n        3 path(s) to be renamed\n\n1. Renaming with number (-r `{nr}`)\n\n        $ brename -d -p '(.+)\\.' -r 'pic-{nr}.' -f .jpg -d\n        Searching for paths to rename...\n\n          [OK] AA.jpg -\u003e pic-1.jpg\n          [OK] b.jpg -\u003e pic-2.jpg\n\n        2 path(s) to be renamed\n\n\n        $ brename -d -p '(.+)\\.' -r 'pic-{nr}.' -f .jpg -d --nr-width 3 --start-num 11\n        Searching for paths to rename...\n\n          [OK] AA.jpg -\u003e pic-011.jpg\n          [OK] b.jpg -\u003e pic-012.jpg\n\n        2 path(s) to be renamed\n\n\n1. Replace submatch with corresponding value via tab delimited key-value file (`-k/--kv-file`)\n\n        $ more kv.tsv\n        a       一\n        b       二\n        c       三\n\n        $ brename -p '^(\\w)' -r '{kv}' -k kv.tsv -K -i -d\n        read key-value file: kv.tsv\n        3 pairs of key-value loaded\n        Searching for paths to rename...\n\n          [OK] AA.html -\u003e 一A.html\n          [OK] AA.jpg -\u003e 一A.jpg\n          [OK] b.jpg -\u003e 二.jpg\n          [unchanged] kv.tsv -\u003e kv.tsv\n\n        3 path(s) to be renamed\n\n1. Auto mkdir\n\n        $ touch a-b-c.txt\n\n        $ brename -f .txt -p '-' -r '/'\n        Searching for paths to rename...\n\n          Done searching.\n\n        Renaming paths...\n\n          [DONE] a-b-c.txt -\u003e a/b/c.txt\n\n        1 path(s) renamed in 0.000 seconds\n\n        $ tree a\n        a\n        └── b\n            └── c.txt\n\n1. Only listing paths that match pattern (`-l` and `-a`)\n\n        $ brename -p '.gz$' -R -l\n        binaries/brename_darwin_386.tar.gz\n        binaries/brename_darwin_amd64.tar.gz\n        binaries/brename_linux_386.tar.gz\n        binaries/brename_linux_amd64.tar.gz\n        binaries/brename_windows_386.exe.tar.gz\n        binaries/brename_windows_amd64.exe.tar.gz\n\n        $ brename -p '.gz$' -R -l -a\n        /home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_darwin_386.tar.gz\n        /home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_darwin_amd64.tar.gz\n        /home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_linux_386.tar.gz\n        /home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_linux_amd64.tar.gz\n        /home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_windows_386.exe.tar.gz\n        /home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_windows_amd64.exe.tar.gz\n\n1. Overwrite mode (`-o/--overwrite-mode`)\n\n        $ ls *.tar.gz\n        brename_darwin_386.tar.gz    brename_linux_386.tar.gz    brename_windows_386.exe.tar.gz\n        brename_darwin_amd64.tar.gz  brename_linux_amd64.tar.gz  brename_windows_amd64.exe.tar.gz\n\n    1. default mode: reporting error\n\n            $ brename -p 386 -r amd64 -d\n            Searching for paths to rename...\n\n              [new path existed] brename_linux_386.tar.gz -\u003e brename_linux_amd64.tar.gz\n              [new path existed] brename_windows_386.exe.tar.gz -\u003e brename_windows_amd64.exe.tar.gz\n\n            2 potential error(s) detected, please check\n\n    1. allowing overwrite\n\n            $ brename -p 386 -r amd64 -d -o 1\n            Searching for paths to rename...\n\n              [new path existed] brename_linux_386.tar.gz -\u003e brename_linux_amd64.tar.gz (will be overwrited)\n              [new path existed] brename_windows_386.exe.tar.gz -\u003e brename_windows_amd64.exe.tar.gz (will be overwrited)\n\n            2 path(s) to be renamed\n\n    1. leave it\n\n            $ brename -p 386 -r amd64 -d -o 2\n            Searching for paths to rename...\n\n              [new path existed] brename_linux_386.tar.gz -\u003e brename_linux_amd64.tar.gz (will NOT be overwrited)\n              [new path existed] brename_windows_386.exe.tar.gz -\u003e brename_windows_amd64.exe.tar.gz (will NOT be overwrited)\n\n            0 path(s) to be renamed\n\n\n## Real-world examples\n\n1. Formating genome assembly file from NCBI.\n    \n        $ ls \n        GCF_029211165.1_ASM2921116v1_genomic.fa\n\n        # ------------------------------------------------------------------------\n        # only keeping accession\n\n        Searching for paths to rename...\n\n        [OK] GCF_029211165.1_ASM2921116v1_genomic.fa -\u003e GCF_029211165.fa\n\n        1 path(s) to be renamed\n\n        # ------------------------------------------------------------------------\n        # keeping accession.version\n        \n        $ brename -R -p '^(\\w{3}_\\d{9}\\.\\d+).+' -r '$1.fa' -d\n        Searching for paths to rename...\n\n          [OK] GCF_029211165.1_ASM2921116v1_genomic.fa -\u003e GCF_029211165.1.fa\n\n        1 path(s) to be renamed\n\n        \n\n\n1. Replace matches with corresponding pairing values\n\n    1. Original files\n\n            $ tree\n            .\n            ├── barcodes.tsv\n            ├── tag_ATGCGTA.fasta\n            ├── tag_CCCCCCC.fasta\n            ├── tag_CGACGTC.fasta\n            ├── tag_TCATAGC.fasta\n            └── tag_TCTATAG.fasta\n\n    1. Tab-delimited key-value file. Notice that `CCCCCCC` is not in it.\n\n            $ cat barcodes.tsv\n            CGACGTC S1\n            ATGCGTA S2\n            TCTATAG S4\n            TCATAGC S3\n\n    1. Renaming tag as sample name, marking `unknown` for non-existing tag.\n\n            $ brename -e -p 'tag_(\\w+)' -r '{kv}' -k barcodes.tsv -m unknown -d\n            [INFO] read key-value file: barcodes.tsv\n            [INFO] 4 pairs of key-value loaded\n            [INFO] checking: [ ok ] 'tag_ATGCGTA.fasta' -\u003e 'S2.fasta'\n            [INFO] checking: [ ok ] 'tag_CCCCCCC.fasta' -\u003e 'unknown.fasta'\n            [INFO] checking: [ ok ] 'tag_CGACGTC.fasta' -\u003e 'S1.fasta'\n            [INFO] checking: [ ok ] 'tag_TCATAGC.fasta' -\u003e 'S3.fasta'\n            [INFO] checking: [ ok ] 'tag_TCTATAG.fasta' -\u003e 'S4.fasta'\n            [INFO] 5 path(s) to be renamed\n\n1. Renaming PDF files for compatibility (moving from `EXT4` to `NTFS` file system):\n\n    1. Original files\n\n            $ tree -Q\n            .\n            ├── \"0000 Test.pdf\"\n            ├── \"2016 SeqKit: A Cross-Platform and Ultrafast Toolkit for FASTA\\342\\201\\204Q File Manipulation .pdf\"\n            ├── \"metagenomics\"\n            │   ├── \"2017 16S rRNA gene sequencing and healthy reference ranges for 28 clinically relevant microbial taxa from the human gut microbiome .pdf\"\n            │   ├── \"2017 De novo assembly of viral quasispecies using overlap graphs .pdf\"\n            │   └── \"2017 Tracking microbial colonization in fecal microbiota transplantation experiments via genome-resolved metagenomics .pdf\"\n            ├── \"test2222222222222222222211111111122222222222222222233333333.pdf\"\n            └── \"test.pdf\"\n\n    1. Removing \"\\n\", \"'\", \"?\".\n\n            $ brename -p \"[\\n'\\?]\" -r \" \" -R\n            \n    1. Replacing \":\" with \" _\"\n\n            $ brename -p \":\" -r \" _\" -R\n\n    1. Shortening file names (prefering spliting with space)\n\n            $ brename -R -f .pdf -i -p \"^(.{30,50})[ \\.].*.pdf\" -r \"\\$1.pdf\" -d\n\n    1. Result\n\n            $ tree -Q\n            .\n            ├── \"0000 Test.pdf\"\n            ├── \"2016 SeqKit _ A Cross-Platform and Ultrafast.pdf\"\n            ├── \"metagenomics\"\n            │   ├── \"2017 16S rRNA gene sequencing and healthy.pdf\"\n            │   ├── \"2017 De novo assembly of viral quasispecies using.pdf\"\n            │   └── \"2017 Tracking microbial colonization in fecal.pdf\"\n            ├── \"test2222222222222222222211111111122222222222222222233333333.pdf\"\n            └── \"test.pdf\"\n\n## FAQs\n\n- [Invalid result with capture variables](https://github.com/shenwei356/brename/issues/33)\n\n## Contact\n\n[Create an issue](https://github.com/shenwei356/brename/issues) to report bugs,\npropose new functions or ask for help.\n\n## License\n\n[MIT License](https://github.com/shenwei356/brename/blob/master/LICENSE)\n\n## Starchart\n\n\u003cimg src=\"https://starchart.cc/shenwei356/brename.svg\" alt=\"Stargazers over time\" style=\"max-width: 100%\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshenwei356%2Fbrename","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshenwei356%2Fbrename","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshenwei356%2Fbrename/lists"}