Multiple file rename in linux

How can I rename many files at once?

I need to rename a bunch of files in order to fix their sort order, therefore I need to be able to do a sort of «find and replace» so I can replace chunks of the filenames at a time. What tools should I use? I prefer GUI but a command line tool recommendation would also be fine.

16 Answers 16

There are a few but I recommend gprename which is a good compromise between usability and functionality.

Other tools are: rename, krename , pyrenamer , cuteRenamer, .

I have use pyrenamer often and sometimes gprename unless the change is very easily done on the command line. The best thing about these GUI’s is the built-in ‘preview’ action. This will save you headaches.

I really like qmv from the renameutils package. It enables you to use your favorite (terminal based) text editor to rename files. I prefer to invoke it with -f do which gives you a single column (one row per file) with filenames. Combined with the power of Vim it gives you all the tools you need to do massive filename editing.

may be a little difficult to handle, but really powerful!

If you like the shell and perl regular expressions I’d recommend rename . It’s as plain as it’s name.

thunar file manager is a GUI with a bulk rename option

it’s not standard on Gnome but can be installed through the software centre

If you are familiar with Emacs, I think nothing beats Dired for this task. Even if you don’t use Emacs that often you may find Dired a handy tool.

sudo aptitude install emacs23-nox

Start Emacs Dired mode for a directory:

Now enter edit directory mode:

C-x C-q (that is Ctrl+x followed by Ctrl+q)

You can now edit the filenames like editing text in every plain text editor. You may even chose to replace the filenames using regular expressions (note that unfortunately Emacs uses a different syntax than PCRE).

For example, to rename files with counter (starting by 1):
M-x replace-regexp (that is Alt+x followed by the string «replace-regexp» typed in the minibuffer at the bottom of the screen).
Replace regexp: DSCN\(6+\).JPG
Replace with: \,(format «P%04d.jpg» (1 + \#))

To reuse a counter in the filename:
M-x replace-regexp
Replace regexp: DSCN\(2+\).JPG
Replace with: \,(format «P%04d.jpg» (string-to-number \1))

C-c C-c (that is Ctrl+c followed by Ctrl+c)

Or alternatively press the following sequence to abort your changes:

C-c Esc (that is Ctrl+c followed by Esc)

I tend to use mmv, which is command-line based, and has a somewhat quirky expression syntax but tend to solve most of my problems.

If you use Nautilus and know how Nautilus Scripts work, you could use nautilus-renamer.

find -execdir rename

This renames files and directories with a regular expression affecting only basenames, for example:

PATH=/usr/bin find . -depth -execdir rename "s/^find/replace/" '<>' \; 
PATH=/usr/bin find . -type f -execdir rename "s/^find/replace/" '<>' \; 

On the command line theres also the possibility to use magic of sed and shell:

ls *.c | sed "s#\(.*\)\.c#mv \0 \1.cpp#" | sh 

That doesn’t seem to work as printed. You might also use ‘#’ or other character instead of «\» as separators in examples for possibly more clarity. e.g., ` ls .c | sed ‘s#([a-z])\.c#\1.cpp#’ ` (This example is not do the rename, just to display the new filename, for simplicity)

Читайте также:  Сбер звук приложение linux

+1 I find it a really nice way (that additionally works across all distros), without installing anything. But I would probably use the -d switch for ls to avoid listing content of directories which might also end with .c (most of the times not an issue, but still ..).

For me the pyRenamer worked the best. Nothing (sadly) comes close to Total Commanders built it renaming tool. pyRenamer doesn’t integrate with Krusader but considering the fact, that you don’t use the renaming tools that often anyway, pyRenamer is a very good option.

rnm file-name -ns new-filename # single file rnm ./* -ns '/n//i/' # files will be sorted and indexed. rnm ./* -rs '/search/new/g' # 'search' in filenames will be replaced with 'new' rnm ./* -ns '/fn//i/' -ss 'search' # only files/directories which contain 'search' in their name will be indexed (renamed). rnm ./* -ns '/fn//id/' -fo # file only mode, directories will be ignored. rnm ./* -ns '/fn//id/' -fo -dp -1 # recursive to subdirectories all the way. etc. 

Personally I use Ant Renamer with Wine because nothing I’ve tried (Métamorphose, PyRenamer, GPRename, KRename) is as powerful, easy to install and easy to use. And it’s still FOSS so I don’t see the problem.

Krename is a KDE GUI for renaming files, generally found in most package managers.

This answer applies to removing leading numbers that may be found in music files such as mp3s. But Krename does mass rename as well.

  1. Load selected files or folder. Krename loads all files in the selected folder, just click on Open without having to individually select all files.
  2. Go to the Destination tab to overwrite or copy files to another folder.
  3. Go to the Filename tab, then to the Advanced Filename tab.
  4. Start by removing the token $ in the Template window. A change takes place in the Renamed window below. No filenames appear, only the file extensions. 3. Image shows that the filenames have been removed, leaving the file extensions.
  5. Click on Insert Part of Filename. and select the parts of the filename you want to keep. This operation will include all the files and the changes will be obvious in the Renamed window below. 4.
  6. Click OK . The files are renamed without the leading numbers. 5. Final results showing.
  7. Finally, click Finished at the bottom right corner.

Источник

All the Ways to Rename Multiple Files in Linux

Linux users may have to rename file frequently and it is very easy to rename a single file. You can just use the mv command to rename one file. There might also be situations where a user or a Linux system administrator may have to rename multiple files at once. This is a completely different case and Linux supports multiple tools and commands to rename multiple files in one go.

In this tutorial, we learn different utilities to rename multiple files in Linux with examples.

Using the Rename Command

Use the rename command to easily rename multiple files or directories. The rename command provides various advanced options that can help you save time while renaming files based on a pattern match.

Installation

The rename command is not preinstalled on several Linux distributions. If the rename command is missing from your Linux computer, then you can manually install it. For example, to install the command on your Ubuntu system, type:

Читайте также:  Linux if equals string

Syntax

The basic syntax of the rename command is as follows:

For example, you can rename the extensions of multiple from .html to .xml using the following rename command:

rename command linux example

More Examples

Rename command supports multiple options that can help you perform different operations. These examples will show you how to use these options:

The most common usage of the rename command is to change the file extension from .html to .sql:

Use the -v option to display rename operation output on the screen:

rename command linux example 2

To change a part of the file name, use the following rename command:

rename -v 's/record/example/' *.html

rename command linux example 3

To change the file names from lowercase to uppercase, use the following rename command:

rename command linux example 4

To rename multiple files that matches a particular pattern, for example the files that contains s or ex:

rename -v 's/(ex|s)ample/record/' *.html

rename command linux example 4

To rename all files with file extension .mp3 in the current directory, type:

The -n option does a trial run and to actually rename files use without it.

Using the Rename Utility

Use the rename utility, known as rename.ul, which is part of util-Linux that enable you to rename multiple files. The rename utility is preinstalled in Ubuntu, Debian, and several other modern Linux distributions. This utility renames multiple files that are present in the current working directory.

We have the following html files in the current working directory:

To rename multiple files without changing the file extensions, use the following rename utility command:

rename.ul record script *.html

This command will rename multiple files in the current directory from record to script. Similarly, you can also change the file extension of all these files as follows:

This command will change extension of all the files in the current directory from .html to .xml.

Using Vimv

You can use the Vimv utility to rename Linux files in a batch. To get this utility on your system from Github, use the following git clone command:

git clone https://github.com/thameera/vimv.git

After you clone the Vimv Git repository on your system, use the cp command to copy the binary file to your $PATH variable and change permissions on this file to make it executable.

sudo cp vimv/vimv /usr/local/bin/ sudo chmod +x /usr/local/bin/vimv

Go to the directory where your files are stored, which you want to rename using the terminal, and run the vimv command.

using vimv to batch rename files

Press ‘i’ to move into the insert mode and bulk rename files. After renaming files, save and quit the vim editor.

Using qmv

Qmv, also known as quick move, utility is part of the renameutils package. Using Qmv, you can bulk rename files in a very short time using a text editor of your choice.

First, install the qmv using the following command:

sudo apt install renameutils

Go to the directory where your files are stored, which you want to rename using the terminal, and run the qmv command.

When you run the qmv command, the following window displays inside the terminal:

using qmv rename multiple files

You can edit the names of the files in the second column and save changes. After renaming files using the qmv, the following output shows on the terminal:

Читайте также:  Линукс изменение размеров окна

Using mmv

Use the mmv utility to bulk rename files based on wildcard patterns.

The mmv utility is not preinstalled on most Linux distributions, so you must first install it using the default package manager on your operating system.

Run the following command on Ubuntu to install mmw:

Use the mmv utility to change the extension of all the files in the current directory. The following example changes the extension of all the files from

For example, we want to change the extension of all files from .sql to .txt using mmv command.

To change all the file names from lowercase to uppercase:

To change the file names back to lowercase, type:

You can also change the file name using the mmv command. For example, you can change the file name ‘example’ to ‘record’ with a similar file number pattern:

Using Thunar File manager

If you do not like working on a command-line interface, then you can use a graphical user interface (GUI) tool to rename multiple files in one go. One such GUI tool is Thunar file manager.

Thunar is one of the most popular file managers of Linux systems. It also provides functionality to rename multiple files. Thunar is not preinstalled on most Linux distributions, and you need to install it manually.

To install Thunar file manager on Ubuntu Linux, try the following command:

1. Launch the bulk file rename interface of the Thunar file manager:

using thunar bulk renaming

2. Click the Plus sign to add files that you want to rename.

3. Select the options to bulk rename files. You can change the file name case, date and time, insert text, automatic numbering, or even replace characters.

4. After you finalize the new names, listed in the New Name column, click Rename Files to confirm the rename operation.

Using Emacs

Using the Emacs text editor, you can also rename multiple files together without installing any extra package or plugin on your system.

1. Open the emacs text editor on your system: emacs

2. Press ‘Alt+X’ to shift on the command mode.

3. Enable the writable directory editor mode: dired

4. Enter the directory path where all files are located which you want to rename: /home/linuxopsys/Documents

5. Press ‘Ctrl+X’ along with ‘Ctrl+Q’ to move into the read/write mode.

emacs dired rename multiple files

6. Change the file names and then press ‘Ctrl+C’ to save changes.

7. Type the ls command to verify changes.

Using Bash

The bash scripts can automate rename operation, same as any other operation that bash files can do. Create a script file as shown in the following example:

Add the following code to the script file that you created:

#!/bin/bash for f in *.sql; do mv -- "$f" "$.pdf" done

Execute the script that will change all file extensions from .sql to .pdf:

Conclusion

Renaming multiple files in one go is not an easy operation and you must know more than one options that you can use. If you are comfortable with bash scripts, then you can use bash to automate rename operations. The Thunar bulk rename operation is also useful for users that are not comfortable using the command-line rename tools.

If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks

Источник

Оцените статью
Adblock
detector