linux中文件重命名_如何在Linux中重命名文件?

linux中文件重命名

This tutorial will walk you through the simple steps to rename a file in Linux.

本教程将引导您完成在Linux中重命名文件的简单步骤。

It’s going to be a very simple and straightforward tutorial even if you are a beginner.

即使您是初学者,这也是一个非常简单明了的教程。

开始之前 (Before we begin)

This tutorial was made on a system running Ubuntu 18.04 on a user with sudo privileges. Most of what you will see in this tutorial can be replicated without any modifications on most of the Linux systems out there.

本教程是在具有sudo特权的用户上运行Ubuntu 18.04的系统上制作的。 您可以在本教程中看到的大部分内容都可以复制,而无需对大多数Linux系统进行任何修改。

But in case you are unable to replicate it, you can try another method from the ones mentioned below.

但是,如果您无法复制它,则可以尝试以下提到的方法中的另一种方法。

在Linux中重命名文件的4种方法 (4 Ways to Rename a File in Linux)

It is easy to rename a file in Linux using a GUI file manager or using the command line when you are dealing with a single file. 

在处理单个文件时,使用GUI文件管理器或使用命令行在Linux中重命名文件很容易。

But if you wish to rename multiple files, using the command line is a better approach. In this tutorial, we will discuss 4 different ways in which we can rename a file in Linux.

但是,如果您想重命名多个文件,则使用命令行是一种更好的方法。 在本教程中,我们将讨论在Linux中重命名文件的4种不同方式。

1.使用mv命令 (1. Using the mv command)

The function of the mv command is to move files. However, as a bonus functionality, it can be used to rename a file in Linux. 

mv命令的功能是移动文件。 但是,作为一项附加功能,它可用于在Linux中重命名文件。


mv [OPTIONS] sourcefile destinationfile

While the mv command can be used to move multiple files or directories, we can enter only one file name each for the source and destination. Hence to rename a file OldName.txt to NewName.txt, we use the following command.

虽然mv命令可用于移动多个文件或目录,但我们只能为源和目标分别输入一个文件名。 因此,要将文件OldName.txt重命名为NewName.txt,我们使用以下命令。


mv OldName.txt NewName.txt

The mv command can be used as part of a bash loop or with the find command to rename multiple files at once. 

mv命令可以用作bash循环的一部分,也可以与find命令一起使用,以一次重命名多个文件。

2.使用重命名命令 (2. Using the rename command)

When we wish to rename multiple files at the same time, we can use a utility designed to rename a file in Linux instead of something that can rename files as an unintended functionality.

当我们希望同时重命名多个文件时,可以使用旨在在Linux中重命名文件的实用程序,而不是可以将文件重命名为意外功能的工具。

This brings us to the rename utility. To use the rename command, we install it on our system using apt or whichever package manager your Linux distro has.

这使我们进入了重命名实用程序。 要使用重命名命令,我们使用apt或您的Linux发行版具有的任何软件包管理器将其安装在系统上。


sudo apt install rename

Once the utility is installed, we can now use the rename command through the command-line. 

安装该实用程序后,我们现在可以通过命令行使用重命名命令。


rename [Options] 's/oldname/newname/' *

This command requires basic knowledge of regular expressions. Here, ‘s’ stands for substitute.

此命令需要正则表达式的基本知识。 在这里,“ s”代表替代品。

The remaining expression is self-explanatory. Using * makes the command run for all files whose name contains oldname.

其余的表达式是不言自明的。 使用*可使命令针对名称包含oldname的所有文件运行。

3.使用renameutils (3. Using renameutils)

The renameutils package provides us with a set of commands to rename a file in Linux. With a focus on batch renaming of files, renameutils consists of five commands.

namedutils软件包为我们提供了一组命令,用于在Linux中重命名文件。 着重于文件的重命名,renameutils由五个命令组成。

However, we will focus on two – qmv (quick move) and imv (interactive move) for this tutorial.

但是,在本教程中,我们将重点介绍两个-qmv(快速移动)和imv(交互式移动)。

To install renameutils on our system, we use the following command.

要在我们的系统上安装namedutils,我们使用以下命令。


sudo apt install renameutils

Once the utility is installed, we can now use the qmv and imv commands through the command-line. 

安装该实用程序后,我们现在可以通过命令行使用qmv和imv命令。

Syntax (qmv):

语法(qmv):


qmv directoryname/

This will open a window where the left column displays the original names of the files. Whereas, the right column is for the name which you wish to set for your files. Edit the right column to set the names you wish for your file.

这将打开一个窗口,其中左列显示文件的原始名称。 而右栏是您要为文件设置的名称。 编辑右列以设置所需的文件名。

Syntax (imv):

语法(imv):


imv directoryname/filename

This will display the address of the file. Simply edit the name to rename the file and press enter to save the change.

这将显示文件的地址。 只需编辑名称以重命名文件,然后按Enter键即可保存更改。

Note that imv only allows you to rename one file at a time.

请注意, imv仅允许您一次重命名一个文件。

4.使用GUI文件管理器 (4. Using a GUI file manager)

We can use the bulk rename utility of the Thunar file manager by installing the GUI file manager Thunar with the below command.

通过使用以下命令安装GUI文件管理器Thunar,我们可以使用Thunar文件管理器的批量重命名实用程序。


sudo apt-get install thunar

Now you can launch the bulk rename utility using the following command.

现在,您可以使用以下命令启动批量重命名实用程序。


thunar -B

You can click the + sign to add files. It allows the following criteria for renaming.

您可以单击+号添加文件。 它允许使用以下条件进行重命名。

  • Insert Date or Time

    插入日期或时间
  • Insert or Overwrite

    插入或覆盖
  • Numbering

    编号
  • Remove Characters

    删除字符
  • Search & Replace

    搜索和替换
  • Uppercase / Lowercase

    大写小写

Once you choose the desired criteria, simply click Rename Files to proceed with the operation.

选择所需的条件后,只需单击“重命名文件”即可继续操作。

结语 (Wrapping up)

Linux based systems offer a wide variety of options to rename a file in Linux. One can use any of these to suit their needs and preferences. We hope this tutorial was able to help you understand different ways to rename a file in Linux.

基于Linux的系统提供了多种选项来重命名Linux中的文件。 可以使用其中任何一种来满足他们的需求和喜好。 我们希望本教程能够帮助您了解在Linux中重命名文件的不同方法。

If you have any feedback, queries or corrections, feel free to leave them in the comments below.

如果您有任何反馈,查询或更正,请随时在下面的评论中保留。

翻译自: https://www.journaldev.com/39181/rename-a-file-in-linux

linux中文件重命名

  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值