好用工具分享--推荐一个好用的跨平台的批量重命名文件或者文件夹工具【f2】

本文介绍了跨平台的命令行工具f2,用于批量重命名文件和目录。通过在Windows上安装、查看用法,以及演示如何搜索和替换文件名中的特定模式,展示了f2在批量文件管理上的便利性。文章还提供了搜索文件夹、正则替换等实用操作,并强调了其在特定场景下的高效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

说明:

今天发现一个好用的工具,可以批量重命名本地文件或者文件夹,可以批量替换。

只是。macos、linux、window多个平台。

GitHub项目地址:

各平台安装使用文档

f2工具使用:

剩下我就摸搜着学习使用下这个工具再windows上如何使用。

1、windows安装:

找到项目的tags目录,然后我现在一个最新的版本。

tag地址

比如,下载地址:https://github.com/ayoisaiah/f2/releases/tag/v1.6.7

我这里选择win64位下载下来。

在这里插入图片描述

下载了然后解压之后,放到不动的盘符,把目录放到添加到环境变量。

2、用法查看:

1、查看用法说明

win+R进入cmd,然后输入:

f2 -h

E:\>f2 -h
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 <ayo@freshman.tech>

VERSION:
   v1.6.7

FLAGS:
     -f, --find <pattern>
         Search pattern. Treated as a regular expression by default unless --string-mode is also used. If omitted, it defaults to the entire file name (including the extension).

     -r, --replace <string>
         Replacement string. If omitted, defaults to an empty string. Supports built-in and regex capture variables. Learn more about variable support here: https://github.com/ayoisaiah/f2/wiki/Built-in-variables

     -u, --undo
         Undo the last operation performed in the current working directory if possible. Learn more: https://github.com/ayoisaiah/f2/wiki/Undoing-a-renaming-operation

OPTIONS:
     -l, --replace-limit <integer>
         Limit the number of replacements to be made on the file name (replaces all matches if set to 0). Can be set to a negative integer to start replacing from the end of the file name.

     -s, --string-mode
         Opt into string literal mode. The presence of this flag causes the search pattern to be treated as a non-regex string.

     -E, --exclude <pattern>
         Exclude files/directories that match the given search pattern. Treated as a regular expression. Multiple exclude patterns can be specified.

     -x, --exec
         Execute the batch renaming operation. This will commit the changes to your filesystem.

     -R, --recursive
         Recursively traverse all directories when searching for matches. Use the --max-depth flag to control the maximum allowed depth (no limit by default).

     -m, --max-depth <integer>
         Positive integer indicating the maximum depth for a recursive search (set to 0 for no limit).

      --sort <sort>
         Sort the matches according to the provided '<sort>'.
          Allowed sort values:
            'default': alphabetical order
            'size': file size
            'mtime': file last modified time
            'btime': file creation time (Windows and macOS only)
            'atime': file last access time
            'ctime': file metadata last change time

      --sortr <sort>
         Same as --sort but presents the matches in the reverse order.

     -i, --ignore-case
         When this flag is provided, the given pattern will be searched case insensitively.

     -q, --quiet
         Activate silent mode which doesn't print out any information including errors

     -e, --ignore-ext
         Ignore the file extension when searching for matches.

     -d, --include-dir
         Include directories when searching for matches as they are exempted by default.

     -D, --only-dir
         Rename only directories, not files (implies --include-dir)

     -H, --hidden
         Include hidden directories and files in the matches (they are skipped by default). A hidden file or directory is one whose name starts with a period (all operating systems) or one whose hidden attribute is set to true (Windows only)

     -F, --fix-conflicts
         Automatically fix conflicts based on predefined rules. Learn more: https://github.com/ayoisaiah/f2/wiki/Validation-and-conflict-detection

      --allow-overwrites
         Allow the overwriting of existing files

     -h, --help
         show help

     -v, --version
         print the version

DOCUMENTATION:
  https://github.com/ayoisaiah/f2/wiki

WEBSITE:
  https://github.com/ayoisaiah/f2

对应的中文翻译解释:
旗帜:
     -f, --find <模式>
         搜索模式。默认情况下将其视为正则表达式,除非还使用了 --string-mode。如果省略,则默认为整个文件名(包括扩展名)。

     -r, --replace <字符串>
         替换字符串。如果省略,则默认为空字符串。支持内置和正则表达式捕获变量。在此处了解有关变量支持的更多信息:https://github.com/ayoisaiah/f2/wiki/Built-in-variables

     -u,--撤消
         如果可能,撤消在当前工作目录中执行的最后一个操作。了解更多:https://github.com/ayoisaiah/f2/wiki/Undoing-a-renaming-operation

选项:
     -l, --replace-limit <整数>
         限制对文件名进行的替换次数(如果设置为 0,则替换所有匹配项)。可以设置为负整数以从文件名末尾开始替换。

     -s, --string-mode
         选择字符串文字模式。此标志的存在导致搜索模式被视为非正则表达式字符串。

     -E, --exclude <模式>
         排除与给定搜索模式匹配的文件/目录。视为正则表达式。可以指定多个排除模式。

     -x, --exec
         执行批量重命名操作。这会将更改提交到您的文件系统。

     -R, --递归
         搜索匹配项时递归遍历所有目录。使用 --max-depth 标志来控制允许的最大深度(默认情况下没有限制)。

     -m, --max-depth <整数>
         正整数表示递归搜索的最大深度(设置为 0 表示没有限制)。

      --sort <排序>
         根据提供的“<sort>”对匹配项进行排序。
          允许的排序值:
            “默认”:字母顺序
            “大小”:文件大小
            'mtime': 文件最后修改时间
            'btime':文件创建时间(仅限 Windows 和 macOS)
            'atime': 文件上次访问时间
            'ctime': 文件元数据上次更改时间

      --sortr <排序>
         与 --sort 相同,但以相反的顺序显示匹配项。

     -i, --ignore-case
         提供此标志时,将不区分大小写地搜索给定模式。

     -q, --安静
         激活不打印任何信息(包括错误)的静默模式

     -e, --ignore-ext
         搜索匹配项时忽略文件扩展名。

     -d, --include-dir
         搜索匹配项时包括目录,因为默认情况下它们是免除的。

     -D, --only-dir
         仅重命名目录,而不重命名文件(暗示 --include-dir)

     -H, --隐藏
         在匹配中包含隐藏的目录和文件(默认情况下会跳过它们)。隐藏文件或目录是名称以句点开头的文件或目录(所有操作系统)或隐藏属性设置为 true 的文件或目录(仅限 Windows)

     -F, --fix-conflicts
         根据预定义的规则自动修复冲突。了解更多:https://github.com/ayoisaiah/f2/wiki/Validation-and-conflict-detection

      --allow-overwrites
         允许覆盖现有文件

     -h, --help
         显示帮助

     -v, --version
         打印版本

2、准备好一个目录文件

查看准备的文件树:

注意点::
window下是:tree /f,linux下是:tree -f

E:\photos\f2-demo>tree /f
卷 data 的文件夹 PATH 列表
卷序列号为 2EC0-3153
E:.
├─76296_顶级迷人美女销魂巨乳酒店人体艺术写真壁纸
│      0.jpg
│
├─76474_清纯双马尾辫美女铁轨写真手机壁纸
│      0.jpg
│      1.jpg
│      2.jpg
│      3.jpg
│      4.jpg
│      5.jpg
│      6.jpg
│      7.jpg
│      8.jpg
│
├─77478_治愈系美女性感露肩私房写真手机壁纸
│      0.jpg
│      1.jpg
│      2.jpg
│
├─78727_居家俏皮美女私房性感写真图片手机壁纸
│      0.jpg
│      1.jpg
│
├─79401_圣诞节元气美女可爱写真图片手机壁纸
│      0.jpg
│      1.jpg
│      2.jpg
│      3.jpg
│      4.jpg
│      5.jpg
│
├─80835_长发美女清纯温婉写真图片手机壁纸
│      0.jpg
│      1.jpg
│      2.jpg
│      3.jpg
│      4.jpg
│      5.jpg
│
├─82663_清纯氧气美女居家养眼写真图片手机壁纸
│      0.jpg
│      1.jpg
│      2.jpg
│      3.jpg
│      4.jpg
│
└─85483_清纯可爱美女私房性感俏皮写真手机壁纸
        0.jpg
        1.jpg


3、常用搜索测试

1)、搜索文件夹或者文件名包含美女的结果
f2 -f 美女 -d -R

搜索结果包括文件夹,需要加入-d参考,默认是不包含文件夹。

我这里搜到修改了几个子目录命名加入“美女”,这样就搜索到了。

在这里插入图片描述

2)、将搜索结果替换预览:
f2 -f 美女 -d -R -r "meinv"

这个时候,本地文件是不会改变的。加入-x才会执行替换。

# 执行之后,不会显示预览界面,直接修改本地文件名和文件夹了
f2 -f 美女 -d -R -r "meinv" -x

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

3)、正则替换:

由于默认是支持正则替换的,然后测试是挺方便的

f2 -f "_.*?meinv" -d -R -r "meimei" -x

对比发现,下划线和meinv直接的目录,都被替换成meimei了。

在这里插入图片描述

总结:

更多用法,看你自己需求吧,我觉得对于一个目录下的有规律的文件重命名什么的,是完全好用。

但是对于一个目录下,子目录过多,或者文件很多【比如上百万,性能就不知道了】

不过再对于批量改名什么的,或者改一部分,简直就是方便的飞起。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhaojiafu666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值