https://ostechnix.com/how-to-rename-multiple-files-at-once-in-linux/
Method 4 - Rename multiple files at once using vimv
As the name says, Vimv is a command line utility to bulk rename files using Vim editor. You can, of course, change the editor by changing the value of $EDITOR
environment variable.
To install Vimv, git clone the repository:
$ git clone https://github.com/thameera/vimv.git
Copy the vimv binary to your $PATH
, for example /usr/local/bin/
.
$ sudo cp vimv/vimv /usr/local/bin/
Finally, make it executable:
$ sudo chmod +x /usr/local/bin/vimv
Now go to the directory and run the following command to edit the filenames.
$ vimv
You will see the filenames in Vi editor. Press i to switch to interactive mode and edit the filenames as the way you edit text in Vi editor. Once done, press ESC
key and type :wq
to save and exit.
The files inside the directory should be renamed now.
Method 3 - Rename files using renameutils
The renameutils is a set of programs that is designed to batch renaming files and directories faster and easier.
Renameutils consists of the following five programs:
- qmv (quick move),
- qcp (quick copy),
- imv (interactive move),
- icp (interactive copy),
- deurlname (delete URL).
Install renameutils in Linux
Renameutils is available in the default repositories of most Linux distributions. To install it on Arch-based systems, enable the community repository and run:
$ sudo pacman -Syu renameutils
On Debian-based systems:
$ sudo apt install renameutils
Now, let us see some examples.
1. qmv
The qmv program will open the filenames in a directory in your default text editor and allows you to edit them.
I have the following three files in a directory named 'ostechnix'.
$ ls ostechnix/ abcd1.txt abcd2.txt abcd3.txt
To rename the filenames in the 'ostechnix' directory, simply do:
$ qmv ostechnix/
Now, change the filenames as you wish. You will see the live preview as you edit the filenames.
Alternatively, you can cd into the directory and simply run 'qmv'
.
Once you opened the files, you will see the two columns as shown in the following screenshot.
The left column side displays the source filenames and the right column displays the destination names (the output filenames that you will get after editing).
Now, rename all the output names on the right side as you wish.
After renaming filenames, save and quit the file.
Finally, you will see the following output:
Plan is valid. abcd1.txt -> xyzd1.txt abcd2.txt -> xyzd2.txt abcd3.txt -> xyzd3.txt Regular rename abcd1.txt -> xyzd1.txt abcd2.txt -> xyzd2.txt abcd3.txt -> xyzd3.txt
Now, check if the changes have actually been made using 'ls'
command:
$ ls ostechnix/ xyzd1.txt xyzd2.txt xyzd3.txt
See? All files are renamed. Not just files, the renameutils will also rename the directory names as well.
Here is a quick video demo of qmv program:
If you don't want to edit the filenames in dual-column format, use the following command to display the destination file column only.
$ qmv -f do ostechnix/
Where, '-f'
refers the format
and 'do'
refers destination-only
.
Now, you will see only the destination column. That's the column we make the changes.
Once done, save and close the file.
For more details, refer man pages.
$ man qmv
No comments:
Post a Comment