One of the ways I quickly rename files in Windows is
F2 > Rename > Tab (to next file) > Rename ...
But in Ubuntu/Nautilus, I can't tab to next file. But being on Linux, I think there must be a command line alternative.
However, sometimes, I may want more control over how to rename specific files. In that case, perhaps its better to be able to tab to the next file
I use
rename
all the time. It is pretty simple, but hopefully you know basic regex:This will replace the string
SEARCH
withREPLACE
in every file (that is,*
). The/g
means global, so if you had aSEARCH_SEARCH.jpg
, it would be renamedREPLACE_REPLACE.jpg
. If you didn't have/g
, it would have only done substitution once, and thus now namedREPLACE_SEARCH.jpg
. If you want case-insensitive, add/i
(that would be,/gi
or/ig
at the end).With regular expressions, you can do lots more.
Note that this
rename
is theprename
(aka Perlrename
) command, which supports complete Perl regular expressions. There is anotherrename
which uses patterns, and is not as powerful.prename
used to be installed by default on Ubuntu (along with Perl), but now you may have to do:Here are a few examples:
Prefix
Add:
document.pdf
renamed toMyPrefix_document.pdf
Remove:
Also you can remove unwanted strings. Let's say you had 20 MP3 files named like
CD RIP 01 Song.mp3
and you wanted to remove the "CD RIP" part, and you wanted to remove that from all of them with one command.CD RIP 01 Song.mp3
to01 Song.mp3
Notice the extra space in
'^CD RIP '
, without the space all files would have a space as the first character of the file. Also note, this will work without the^
character, but would matchCD RIP
in any part of the filename. The^
guarantees it only removes the characters if they are the beginning of the file.Suffix
Add:
document.pdf
renamed todocument.pdf_MySuffix
Change:
will change
Something.pdf
intoSomething.doc
. (The reason for the backslash is,.
is a wildcard character in regexp so.pdf
matchesqPDF
whereas\.pdf
only matches the exact string.pdf
. Also very important to note, if you are not familiar with BASH, you must put backslashes in SINGLE quotes! You may not omit quotes or use double quotes, or bash will try to translate them. To bash\.
and"\."
equals.
. (But double-quotes and backslashes are used, for example "\n" for a newline, but since"\."
isn't a valid back escape sequence, it translates into.
)Actually, you can even enclose the parts of the string in quotes instead of the whole:
's/Search/Replace/g'
is the same ass/'Search'/'Replace'/g
ands/Search/Replace/g
to BASH. You just have to be careful about special characters (and spaces).I suggest using the
-n
option when you are not positive you have the correct regular expressions. It shows what would be renamed, then exits without doing it. For example:This will list all changes it would have made, had you not put the
-n
flag there. If it looks good, press Up to go back, then erase the-n
and press Enter (or replace it with-v
to output all changes it makes).Note: Ubuntu versions above 17.04 don't ship with
rename
by default, however it's still available in the repositories. Usesudo apt install rename
to install itTry pyrenamer.
It's not integrated with nautilus, but it gets the job done. Here is a review.
Thunar (part of XFCE) also has a renamer that you can run separately.
There seems to be a project on launchpad called nautilus-renamer. You can install it by running
make install
once you download the script and untar it. It seems to have some functionalities or if you do know some programming may be you could just enhance it to your need as it is just a python script.Not really the same question as How can rename many files at once? but I'm going to suggest the same program that I suggested in that answer: qmv.
qmv is a handy tool from the renameutils package. It enables you to use your favorite text editor to rename files. Combined with the power of vim, you have an excellent renaming utility.
I usually invoke it like
qmv -f do
in the dir where I want to rename a bunch of files. Or if I want to rename recursivelyqmv -R -f do
.Whenever I have the need to rename multiple files, I always fall back on qmv (and vim).
http://www.nongnu.org/renameutils/
In the command line, to rename a single file the command is simply
If you want to do it in batch, you'll probably want to do it via a script. If you provide more details I or someone else can probably whip one up for you. That said, a script to append stuff to a file might look like this:
Depending on exactly how you need things renamed this will likely be tweaked, for instance if you have specific renaming rules to follow. (Personally I'd do this via a Perl script since my bash-foo is not that great, but that's just me.)
Note that I got the separation of filename and extension from a previously asked question.
In case you want to do it without command line, similarly to what you have been doing in Windows, use right arrow key instead of tab key. This will select the next file just as tab does in Windows.
If the only suitable option is renaming the files manually, a great way to do that is using
vidir
(in themoreutils
package):Examples
Renaming files selectively
Current working directory's content:
Run
vidir
, rename the filenames in the lines containing the filenames you wish to rename; hit CTRL+O and CTRL+X:Switching filenames selectively
Current working directory's content:
Current working directory's files' content:
Run
vidir
, switch the numbers in the lines containing the filenames you wish to switch; hit CTRL+O and CTRL+X:Removing files selectively
Current working directory's content:
Run
vidir
, remove the lines containing the files you wish to delete; hit CTRL+O and CTRL+X:I'm using krename. It is a GUI app. It could read mp3 tags and so on.
It exists as a separate app as well as a part of Krusader.
There's also a
rename
script - which is a part of standard perl installation (You probably have it installed). Check it out withman rename
.