Go項(xiàng)目推薦:一個(gè)快速安全的批量重命名開源工具
F2 是一個(gè)快捷鍵,進(jìn)行文件重命名。今天推薦一個(gè)開源工具,它的名字就叫做 f2,是一個(gè)跨平臺(tái)、快速、安全的批量重命名工具。
項(xiàng)目地址:https://github.com/ayoisaiah/f2,剛開源,使用 Go 語言實(shí)現(xiàn)的。

它核心的特色是安全和快速。在速度方面,對(duì)比了幾個(gè)工具:
rnm[1] (C++) — v4.0.9 rnr[2] (Rust) — v0.3.0 brename[3] (Go) — v2.11.0
f2 的結(jié)論是它比以上工具都快 2~3 倍。
具體其他特色有:
跨平臺(tái),支持 Linux、MacOS 和 Windows; 支持正則表達(dá)式過濾文件,并支持分組; 安全,體現(xiàn)在默認(rèn)執(zhí)行改名操作,而是預(yù)覽,只有告訴它改名它才執(zhí)行; 支持遞歸重命名; 支持撤回; 。。。
安裝該工具,可以通過 go get 安裝,也可以通過 npm 安裝,因?yàn)榘l(fā)布到了 npm 上:
$ npm i @ayoisaiah/f2 -g
以下是 f2 的命名幫助文檔:
DESCRIPTION:
F2 is a command-line tool for batch renaming multiple files and directories quickly and safely
USAGE:
f2 FLAGS [OPTIONS] [PATHS...]
AUTHOR:
Ayooluwa Isaiah <[email protected]>
VERSION:
v1.1.0
FLAGS:
--find string, -f string Search string or regular expression.
--replace string, -r string Replacement string. If omitted, defaults to an empty string.
--start-num value, -n value Starting number when using numbering scheme in replacement string such as %03d (default: 1)
--output-file value, -o value Output a map file for the current operation
--exec, -x Execute the batch renaming operation (default: false)
--recursive, -R Rename files recursively (default: false)
--undo value, -u value Undo a successful operation using a previously created map file
--ignore-case, -i Ignore case (default: false)
--ignore-ext, -e Ignore extension (default: false)
--include-dir, -d Include directories (default: false)
--only-dir, -D Rename only directories (implies include-dir) (default: false)
--hidden, -H Include hidden files and directories (default: false)
--fix-conflicts, -F Fix any detected conflicts with auto indexing (default: false)
--help, -h show help (default: false)
--version, -v print the version (default: false)
WEBSITE:
https://github.com/ayoisaiah/f2
看一個(gè)具體簡單的例子:
$ f2 -f 'Screenshot' -r 'Image'
+--------------------+---------------+--------+
| INPUT | OUTPUT | STATUS |
+--------------------+---------------+--------+
| Screenshot (1).png | Image (1).png | ok |
| Screenshot (2).png | Image (2).png | ok |
| Screenshot (3).png | Image (3).png | ok |
+--------------------+---------------+--------+
當(dāng)不提供 -x Flag 時(shí),只是展示改名后的樣子,只有加上了 -x,才會(huì)真正的執(zhí)行改名操作。
在項(xiàng)目主頁提供了其他例子供參考。
此外,如果你是一個(gè) Go 愛好者,可以學(xué)習(xí)下它的源碼,它使用了 github.com/urfave/cli 這個(gè)庫,我也是很喜歡這個(gè)庫。學(xué)習(xí)開源項(xiàng)目源碼,對(duì)自己能力會(huì)很有幫助。
參考資料
rnm: https://github.com/neurobin/rnm
[2]rnr: https://github.com/ChuckDaniels87/rnr
[3]brename: https://github.com/shenwei356/brename
文末「閱讀原文」可直達(dá)項(xiàng)目首頁。
今天的項(xiàng)目大家覺得怎么樣嗎?如果你喜歡,請(qǐng)?jiān)谖恼碌撞苛粞浴Ⅻc(diǎn)贊或關(guān)注轉(zhuǎn)發(fā),你的支持就是我持續(xù)更新的最大動(dòng)力!
推薦閱讀
