首页 > 编程知识 正文

linux显示当前路径,python重命名文件

时间:2023-05-03 17:54:15 阅读:20915 作者:3407

在linux上重命名文件

thistutorialwillwalkyouthroughthesimplestepstorenameafileinlinux。

本教程介绍了在Linux上重命名文件的简单过程。

it’sgoingtobeaverysimpleandstraightforwardtutorialevenifyouareabeginner。

即使是初学者,这也是非常容易理解的教程。

之前(Before we begin ) ) ) )。 thistutorialwasmadeonasystemrunningubuntu 18.04 onauserwithsudoprivileges.mostofwhatyouwillseeinthistutorialcanbereplicatededw itede

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

butincaseyouareunabletoreplicateit,youcantryanothermethodfromtheonesmentionedbelow。

但是,如果无法复制,请尝试以下方法之一:

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

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

utifyouwishtorenamemultiplefiles,usingthecommandlineisabetterapproach.in this tutorial,we will discuss4differentwaysinwhich

但是,如果要重命名多个文件,建议使用命令行。 本教程介绍了在Linux上重命名文件的四种不同方法。

1.mv命令(1. Using the mv command ) thefunctionofthemvcommandistomovefiles.however,as a bonus functionality,itcanbeusedtoror

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

mv [选项] sourcefiledestinationfilewhilethemvcommandcanbeusedtomovemultiplefilesordirectories, wecanenteronlyonefilenameeachforthesourceanddestination.hencetorenameafileoldname.txtto newname.txt,weusethefolowingcord

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

mv old name.txt newname.txtthemvcommandcanbeusedaspartofabashlooporwiththefindcommandtorenamemultiplefilesatonce。

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

2 .重命名命令(2.使用重命名命令) whenwewishtorenamemultiplefilesatthesametime,wecanuseautilitydesignedtorenameafiletime

y.

当我们希望同时重命名多个文件时,可以使用旨在在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中文件重命名

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。