How do I easily rename multiple files using command line?
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
command-line rename
add a comment |
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
command-line rename
1
Could you define "more control"? Not sure what you're asking exactly..
– Dang Khoa
Aug 25 '11 at 2:08
I think this question is not answered. What you are asking for (F2 and then jump in F2 mode to the next file) is currently not available I think in Nautilus.
– don.joey
Jul 16 '13 at 20:14
add a comment |
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
command-line rename
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
command-line rename
command-line rename
edited Oct 22 '18 at 11:18
muru
1
1
asked Aug 25 '11 at 1:18
Jiew Meng
3,299206391
3,299206391
1
Could you define "more control"? Not sure what you're asking exactly..
– Dang Khoa
Aug 25 '11 at 2:08
I think this question is not answered. What you are asking for (F2 and then jump in F2 mode to the next file) is currently not available I think in Nautilus.
– don.joey
Jul 16 '13 at 20:14
add a comment |
1
Could you define "more control"? Not sure what you're asking exactly..
– Dang Khoa
Aug 25 '11 at 2:08
I think this question is not answered. What you are asking for (F2 and then jump in F2 mode to the next file) is currently not available I think in Nautilus.
– don.joey
Jul 16 '13 at 20:14
1
1
Could you define "more control"? Not sure what you're asking exactly..
– Dang Khoa
Aug 25 '11 at 2:08
Could you define "more control"? Not sure what you're asking exactly..
– Dang Khoa
Aug 25 '11 at 2:08
I think this question is not answered. What you are asking for (F2 and then jump in F2 mode to the next file) is currently not available I think in Nautilus.
– don.joey
Jul 16 '13 at 20:14
I think this question is not answered. What you are asking for (F2 and then jump in F2 mode to the next file) is currently not available I think in Nautilus.
– don.joey
Jul 16 '13 at 20:14
add a comment |
8 Answers
8
active
oldest
votes
I use rename
all the time. It is pretty simple, but hopefully you know basic regex:
rename "s/SEARCH/REPLACE/g" *
This will replace the string SEARCH
with REPLACE
in every file (that is, *
). The /g
means global, so if you had a SEARCH_SEARCH.jpg
, it would be renamed REPLACE_REPLACE.jpg
. If you didn't have /g
, it would have only done substitution once, and thus now named REPLACE_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 the prename
(aka Perl rename
) command, which supports complete Perl regular expressions. There is another rename
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:
sudo apt install rename
Here are a few examples:
Prefix
Add:
rename 's/^/MyPrefix_/' *
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.
rename 's/^CD RIP //' *
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 match CD RIP
in any part of the filename. The ^
guarantees it only removes the characters if they are the beginning of the file.
Suffix
Add:
rename 's/$/_MySuffix/' *
document.pdf
renamed todocument.pdf_MySuffix
Change:
rename 's/.pdf$/.doc/' *
will change Something.pdf
into Something.doc
. (The reason for the backslash is, .
is a wildcard character in regexp so .pdf
matches qPDF
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 as s/'Search'/'Replace'/g
and s/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:
rename -n s/'One'/'Two'/g *
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. Use sudo apt install rename
to install it
How will I have a "dynamic" suffix. Like 001 - 010 etc. Possible?
– Jiew Meng
Aug 27 '11 at 8:01
Hmm.. I tried to write something up but it didn't work. Mostly because, when I add 1 to 001, it adds to 2, not 002. Otherwise, I could just use varaibles to hold the number position, then append it. Also, I just remembered, before I knew about therename
commmand, this is what I did to append:for f in *; do mv -v "$f" "prependThis$f"; done
– Matt
Aug 27 '11 at 13:54
2
@jiewmeng Yes. Use(?:.[0-9]{3})$
in your pattern, it will match all 3 digit file extensions in a passive group. Example:rename s/^my_favorite_movie.avi(?:.[0-9]{3})$/random_movie.avi/ *
. Have a look at this regex cheat sheet.
– sergio91pt
Aug 30 '11 at 11:33
@sergio91pt it is a nice regex cheat sheet. But what it is about? Must be perl - but a can't find such a note there.
– Adobe
Aug 30 '11 at 16:48
@Adobe Its a general one for "perl based regex". Look at the note about the + sign and the column about POSIX Character Classes.
– sergio91pt
Aug 30 '11 at 18:03
add a comment |
Try 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.
1
thanks for mentioning Thunar functionality. If you have Thunar - select files in folder and press F2.
– Max
Aug 8 '15 at 5:54
add a comment |
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.
add a comment |
In the command line, to rename a single file the command is simply
mv file1.txt file2.txt
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:
#!/bin/bash
for file in *
do
# separate the file name from its extension
if [[ $file == *.* ]]; then
ext="${file##*.}"
fname="${file%.*}"
mv "$file" "${fname}_APPENDSTUFFHERE.$ext"
else
mv "$file" "${file}_APPENDSTUFFHERE"
fi
done
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.
add a comment |
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.
It is not the same: you would still need ENTER to finish renaming, arrow key to move to the next file, and F2 to rename it. TAB does it in 1 step once you are renaming a file.
– MestreLion
Aug 30 '11 at 18:25
@MestreLion But it's very similar to algorithm described in the question and does not require neither any additional software nor command-line operations. Sort of being user-friendly.
– Rafał Cieślak
Aug 30 '11 at 19:31
True, you were the only answer that at least tried the same approach as the original question. And the sad truth is that Nautilus has no such functionality. You can F2 to rename, but thats it. No TAB to automatically jump you to next file in rename mode already.
– MestreLion
Aug 31 '11 at 5:18
add a comment |
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 recursively qmv -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/
I just tried this based on your suggestion. This is really the most awesome tool if you use vim!
– ste_kwr
Aug 14 '14 at 0:07
add a comment |
If the only suitable option is renaming the files manually, a great way to do that is using vidir
(in the moreutils
package):
sudo add-apt-repository universe && sudo apt-get update && sudo apt-get install moreutils
DESCRIPTION
vidir allows editing of the contents of a directory in a text editor.
If no directory is specified, the current directory is edited.
When editing a directory, each item in the directory will appear on
its own numbered line. These numbers are how vidir keeps track of what
items are changed. Delete lines to remove files from the directory, or
edit filenames to rename files. You can also switch pairs of numbers
to swap filenames.
Note that if "-" is specified as the directory to edit, it reads a
list of filenames from stdin and displays those for editing.
Alternatively, a list of files can be specified on the command line.
Examples
Renaming files selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Run vidir
, rename the filenames in the lines containing the filenames you wish to rename; hit CTRL+O and CTRL+X:
.
├── bar.bak
├── baz.old
└── foo.new
Switching filenames selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Current working directory's files' content:
$ for f in *; do printf '- %s:nn' "$f"; cat "$f"; echo; done
- bar:
This is bar
- baz:
This is baz
- foo:
This is foo
$
Run vidir
, switch the numbers in the lines containing the filenames you wish to switch; hit CTRL+O and CTRL+X:
.
├── bar
├── baz
└── foo
$ for f in *; do printf '- %s:nn' "$f"; cat "$f"; echo; done
- bar:
This is foo
- baz:
This is bar
- foo:
This is baz
$
Removing files selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Run vidir
, remove the lines containing the files you wish to delete; hit CTRL+O and CTRL+X:
.
└── baz
add a comment |
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 with man rename
.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f58546%2fhow-do-i-easily-rename-multiple-files-using-command-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
I use rename
all the time. It is pretty simple, but hopefully you know basic regex:
rename "s/SEARCH/REPLACE/g" *
This will replace the string SEARCH
with REPLACE
in every file (that is, *
). The /g
means global, so if you had a SEARCH_SEARCH.jpg
, it would be renamed REPLACE_REPLACE.jpg
. If you didn't have /g
, it would have only done substitution once, and thus now named REPLACE_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 the prename
(aka Perl rename
) command, which supports complete Perl regular expressions. There is another rename
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:
sudo apt install rename
Here are a few examples:
Prefix
Add:
rename 's/^/MyPrefix_/' *
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.
rename 's/^CD RIP //' *
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 match CD RIP
in any part of the filename. The ^
guarantees it only removes the characters if they are the beginning of the file.
Suffix
Add:
rename 's/$/_MySuffix/' *
document.pdf
renamed todocument.pdf_MySuffix
Change:
rename 's/.pdf$/.doc/' *
will change Something.pdf
into Something.doc
. (The reason for the backslash is, .
is a wildcard character in regexp so .pdf
matches qPDF
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 as s/'Search'/'Replace'/g
and s/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:
rename -n s/'One'/'Two'/g *
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. Use sudo apt install rename
to install it
How will I have a "dynamic" suffix. Like 001 - 010 etc. Possible?
– Jiew Meng
Aug 27 '11 at 8:01
Hmm.. I tried to write something up but it didn't work. Mostly because, when I add 1 to 001, it adds to 2, not 002. Otherwise, I could just use varaibles to hold the number position, then append it. Also, I just remembered, before I knew about therename
commmand, this is what I did to append:for f in *; do mv -v "$f" "prependThis$f"; done
– Matt
Aug 27 '11 at 13:54
2
@jiewmeng Yes. Use(?:.[0-9]{3})$
in your pattern, it will match all 3 digit file extensions in a passive group. Example:rename s/^my_favorite_movie.avi(?:.[0-9]{3})$/random_movie.avi/ *
. Have a look at this regex cheat sheet.
– sergio91pt
Aug 30 '11 at 11:33
@sergio91pt it is a nice regex cheat sheet. But what it is about? Must be perl - but a can't find such a note there.
– Adobe
Aug 30 '11 at 16:48
@Adobe Its a general one for "perl based regex". Look at the note about the + sign and the column about POSIX Character Classes.
– sergio91pt
Aug 30 '11 at 18:03
add a comment |
I use rename
all the time. It is pretty simple, but hopefully you know basic regex:
rename "s/SEARCH/REPLACE/g" *
This will replace the string SEARCH
with REPLACE
in every file (that is, *
). The /g
means global, so if you had a SEARCH_SEARCH.jpg
, it would be renamed REPLACE_REPLACE.jpg
. If you didn't have /g
, it would have only done substitution once, and thus now named REPLACE_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 the prename
(aka Perl rename
) command, which supports complete Perl regular expressions. There is another rename
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:
sudo apt install rename
Here are a few examples:
Prefix
Add:
rename 's/^/MyPrefix_/' *
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.
rename 's/^CD RIP //' *
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 match CD RIP
in any part of the filename. The ^
guarantees it only removes the characters if they are the beginning of the file.
Suffix
Add:
rename 's/$/_MySuffix/' *
document.pdf
renamed todocument.pdf_MySuffix
Change:
rename 's/.pdf$/.doc/' *
will change Something.pdf
into Something.doc
. (The reason for the backslash is, .
is a wildcard character in regexp so .pdf
matches qPDF
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 as s/'Search'/'Replace'/g
and s/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:
rename -n s/'One'/'Two'/g *
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. Use sudo apt install rename
to install it
How will I have a "dynamic" suffix. Like 001 - 010 etc. Possible?
– Jiew Meng
Aug 27 '11 at 8:01
Hmm.. I tried to write something up but it didn't work. Mostly because, when I add 1 to 001, it adds to 2, not 002. Otherwise, I could just use varaibles to hold the number position, then append it. Also, I just remembered, before I knew about therename
commmand, this is what I did to append:for f in *; do mv -v "$f" "prependThis$f"; done
– Matt
Aug 27 '11 at 13:54
2
@jiewmeng Yes. Use(?:.[0-9]{3})$
in your pattern, it will match all 3 digit file extensions in a passive group. Example:rename s/^my_favorite_movie.avi(?:.[0-9]{3})$/random_movie.avi/ *
. Have a look at this regex cheat sheet.
– sergio91pt
Aug 30 '11 at 11:33
@sergio91pt it is a nice regex cheat sheet. But what it is about? Must be perl - but a can't find such a note there.
– Adobe
Aug 30 '11 at 16:48
@Adobe Its a general one for "perl based regex". Look at the note about the + sign and the column about POSIX Character Classes.
– sergio91pt
Aug 30 '11 at 18:03
add a comment |
I use rename
all the time. It is pretty simple, but hopefully you know basic regex:
rename "s/SEARCH/REPLACE/g" *
This will replace the string SEARCH
with REPLACE
in every file (that is, *
). The /g
means global, so if you had a SEARCH_SEARCH.jpg
, it would be renamed REPLACE_REPLACE.jpg
. If you didn't have /g
, it would have only done substitution once, and thus now named REPLACE_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 the prename
(aka Perl rename
) command, which supports complete Perl regular expressions. There is another rename
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:
sudo apt install rename
Here are a few examples:
Prefix
Add:
rename 's/^/MyPrefix_/' *
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.
rename 's/^CD RIP //' *
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 match CD RIP
in any part of the filename. The ^
guarantees it only removes the characters if they are the beginning of the file.
Suffix
Add:
rename 's/$/_MySuffix/' *
document.pdf
renamed todocument.pdf_MySuffix
Change:
rename 's/.pdf$/.doc/' *
will change Something.pdf
into Something.doc
. (The reason for the backslash is, .
is a wildcard character in regexp so .pdf
matches qPDF
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 as s/'Search'/'Replace'/g
and s/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:
rename -n s/'One'/'Two'/g *
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. Use sudo apt install rename
to install it
I use rename
all the time. It is pretty simple, but hopefully you know basic regex:
rename "s/SEARCH/REPLACE/g" *
This will replace the string SEARCH
with REPLACE
in every file (that is, *
). The /g
means global, so if you had a SEARCH_SEARCH.jpg
, it would be renamed REPLACE_REPLACE.jpg
. If you didn't have /g
, it would have only done substitution once, and thus now named REPLACE_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 the prename
(aka Perl rename
) command, which supports complete Perl regular expressions. There is another rename
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:
sudo apt install rename
Here are a few examples:
Prefix
Add:
rename 's/^/MyPrefix_/' *
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.
rename 's/^CD RIP //' *
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 match CD RIP
in any part of the filename. The ^
guarantees it only removes the characters if they are the beginning of the file.
Suffix
Add:
rename 's/$/_MySuffix/' *
document.pdf
renamed todocument.pdf_MySuffix
Change:
rename 's/.pdf$/.doc/' *
will change Something.pdf
into Something.doc
. (The reason for the backslash is, .
is a wildcard character in regexp so .pdf
matches qPDF
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 as s/'Search'/'Replace'/g
and s/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:
rename -n s/'One'/'Two'/g *
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. Use sudo apt install rename
to install it
edited Dec 15 '18 at 12:14
Sergiy Kolodyazhnyy
69.7k9144306
69.7k9144306
answered Aug 25 '11 at 13:45
Matt
6,37183550
6,37183550
How will I have a "dynamic" suffix. Like 001 - 010 etc. Possible?
– Jiew Meng
Aug 27 '11 at 8:01
Hmm.. I tried to write something up but it didn't work. Mostly because, when I add 1 to 001, it adds to 2, not 002. Otherwise, I could just use varaibles to hold the number position, then append it. Also, I just remembered, before I knew about therename
commmand, this is what I did to append:for f in *; do mv -v "$f" "prependThis$f"; done
– Matt
Aug 27 '11 at 13:54
2
@jiewmeng Yes. Use(?:.[0-9]{3})$
in your pattern, it will match all 3 digit file extensions in a passive group. Example:rename s/^my_favorite_movie.avi(?:.[0-9]{3})$/random_movie.avi/ *
. Have a look at this regex cheat sheet.
– sergio91pt
Aug 30 '11 at 11:33
@sergio91pt it is a nice regex cheat sheet. But what it is about? Must be perl - but a can't find such a note there.
– Adobe
Aug 30 '11 at 16:48
@Adobe Its a general one for "perl based regex". Look at the note about the + sign and the column about POSIX Character Classes.
– sergio91pt
Aug 30 '11 at 18:03
add a comment |
How will I have a "dynamic" suffix. Like 001 - 010 etc. Possible?
– Jiew Meng
Aug 27 '11 at 8:01
Hmm.. I tried to write something up but it didn't work. Mostly because, when I add 1 to 001, it adds to 2, not 002. Otherwise, I could just use varaibles to hold the number position, then append it. Also, I just remembered, before I knew about therename
commmand, this is what I did to append:for f in *; do mv -v "$f" "prependThis$f"; done
– Matt
Aug 27 '11 at 13:54
2
@jiewmeng Yes. Use(?:.[0-9]{3})$
in your pattern, it will match all 3 digit file extensions in a passive group. Example:rename s/^my_favorite_movie.avi(?:.[0-9]{3})$/random_movie.avi/ *
. Have a look at this regex cheat sheet.
– sergio91pt
Aug 30 '11 at 11:33
@sergio91pt it is a nice regex cheat sheet. But what it is about? Must be perl - but a can't find such a note there.
– Adobe
Aug 30 '11 at 16:48
@Adobe Its a general one for "perl based regex". Look at the note about the + sign and the column about POSIX Character Classes.
– sergio91pt
Aug 30 '11 at 18:03
How will I have a "dynamic" suffix. Like 001 - 010 etc. Possible?
– Jiew Meng
Aug 27 '11 at 8:01
How will I have a "dynamic" suffix. Like 001 - 010 etc. Possible?
– Jiew Meng
Aug 27 '11 at 8:01
Hmm.. I tried to write something up but it didn't work. Mostly because, when I add 1 to 001, it adds to 2, not 002. Otherwise, I could just use varaibles to hold the number position, then append it. Also, I just remembered, before I knew about the
rename
commmand, this is what I did to append: for f in *; do mv -v "$f" "prependThis$f"; done
– Matt
Aug 27 '11 at 13:54
Hmm.. I tried to write something up but it didn't work. Mostly because, when I add 1 to 001, it adds to 2, not 002. Otherwise, I could just use varaibles to hold the number position, then append it. Also, I just remembered, before I knew about the
rename
commmand, this is what I did to append: for f in *; do mv -v "$f" "prependThis$f"; done
– Matt
Aug 27 '11 at 13:54
2
2
@jiewmeng Yes. Use
(?:.[0-9]{3})$
in your pattern, it will match all 3 digit file extensions in a passive group. Example: rename s/^my_favorite_movie.avi(?:.[0-9]{3})$/random_movie.avi/ *
. Have a look at this regex cheat sheet.– sergio91pt
Aug 30 '11 at 11:33
@jiewmeng Yes. Use
(?:.[0-9]{3})$
in your pattern, it will match all 3 digit file extensions in a passive group. Example: rename s/^my_favorite_movie.avi(?:.[0-9]{3})$/random_movie.avi/ *
. Have a look at this regex cheat sheet.– sergio91pt
Aug 30 '11 at 11:33
@sergio91pt it is a nice regex cheat sheet. But what it is about? Must be perl - but a can't find such a note there.
– Adobe
Aug 30 '11 at 16:48
@sergio91pt it is a nice regex cheat sheet. But what it is about? Must be perl - but a can't find such a note there.
– Adobe
Aug 30 '11 at 16:48
@Adobe Its a general one for "perl based regex". Look at the note about the + sign and the column about POSIX Character Classes.
– sergio91pt
Aug 30 '11 at 18:03
@Adobe Its a general one for "perl based regex". Look at the note about the + sign and the column about POSIX Character Classes.
– sergio91pt
Aug 30 '11 at 18:03
add a comment |
Try 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.
1
thanks for mentioning Thunar functionality. If you have Thunar - select files in folder and press F2.
– Max
Aug 8 '15 at 5:54
add a comment |
Try 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.
1
thanks for mentioning Thunar functionality. If you have Thunar - select files in folder and press F2.
– Max
Aug 8 '15 at 5:54
add a comment |
Try 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.
Try 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.
edited Feb 16 '17 at 13:22
muru
1
1
answered Aug 25 '11 at 1:37
RolandiXor♦
44.4k25140229
44.4k25140229
1
thanks for mentioning Thunar functionality. If you have Thunar - select files in folder and press F2.
– Max
Aug 8 '15 at 5:54
add a comment |
1
thanks for mentioning Thunar functionality. If you have Thunar - select files in folder and press F2.
– Max
Aug 8 '15 at 5:54
1
1
thanks for mentioning Thunar functionality. If you have Thunar - select files in folder and press F2.
– Max
Aug 8 '15 at 5:54
thanks for mentioning Thunar functionality. If you have Thunar - select files in folder and press F2.
– Max
Aug 8 '15 at 5:54
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Feb 3 '18 at 8:12
dessert
22.2k56198
22.2k56198
answered Aug 25 '11 at 7:06
sagarchalise
17.8k105874
17.8k105874
add a comment |
add a comment |
In the command line, to rename a single file the command is simply
mv file1.txt file2.txt
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:
#!/bin/bash
for file in *
do
# separate the file name from its extension
if [[ $file == *.* ]]; then
ext="${file##*.}"
fname="${file%.*}"
mv "$file" "${fname}_APPENDSTUFFHERE.$ext"
else
mv "$file" "${file}_APPENDSTUFFHERE"
fi
done
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.
add a comment |
In the command line, to rename a single file the command is simply
mv file1.txt file2.txt
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:
#!/bin/bash
for file in *
do
# separate the file name from its extension
if [[ $file == *.* ]]; then
ext="${file##*.}"
fname="${file%.*}"
mv "$file" "${fname}_APPENDSTUFFHERE.$ext"
else
mv "$file" "${file}_APPENDSTUFFHERE"
fi
done
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.
add a comment |
In the command line, to rename a single file the command is simply
mv file1.txt file2.txt
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:
#!/bin/bash
for file in *
do
# separate the file name from its extension
if [[ $file == *.* ]]; then
ext="${file##*.}"
fname="${file%.*}"
mv "$file" "${fname}_APPENDSTUFFHERE.$ext"
else
mv "$file" "${file}_APPENDSTUFFHERE"
fi
done
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 the command line, to rename a single file the command is simply
mv file1.txt file2.txt
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:
#!/bin/bash
for file in *
do
# separate the file name from its extension
if [[ $file == *.* ]]; then
ext="${file##*.}"
fname="${file%.*}"
mv "$file" "${fname}_APPENDSTUFFHERE.$ext"
else
mv "$file" "${file}_APPENDSTUFFHERE"
fi
done
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.
edited Feb 3 '18 at 8:13
dessert
22.2k56198
22.2k56198
answered Aug 25 '11 at 2:19
Dang Khoa
364523
364523
add a comment |
add a comment |
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.
It is not the same: you would still need ENTER to finish renaming, arrow key to move to the next file, and F2 to rename it. TAB does it in 1 step once you are renaming a file.
– MestreLion
Aug 30 '11 at 18:25
@MestreLion But it's very similar to algorithm described in the question and does not require neither any additional software nor command-line operations. Sort of being user-friendly.
– Rafał Cieślak
Aug 30 '11 at 19:31
True, you were the only answer that at least tried the same approach as the original question. And the sad truth is that Nautilus has no such functionality. You can F2 to rename, but thats it. No TAB to automatically jump you to next file in rename mode already.
– MestreLion
Aug 31 '11 at 5:18
add a comment |
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.
It is not the same: you would still need ENTER to finish renaming, arrow key to move to the next file, and F2 to rename it. TAB does it in 1 step once you are renaming a file.
– MestreLion
Aug 30 '11 at 18:25
@MestreLion But it's very similar to algorithm described in the question and does not require neither any additional software nor command-line operations. Sort of being user-friendly.
– Rafał Cieślak
Aug 30 '11 at 19:31
True, you were the only answer that at least tried the same approach as the original question. And the sad truth is that Nautilus has no such functionality. You can F2 to rename, but thats it. No TAB to automatically jump you to next file in rename mode already.
– MestreLion
Aug 31 '11 at 5:18
add a comment |
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.
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.
answered Aug 25 '11 at 15:13
Rafał Cieślak
14.3k54886
14.3k54886
It is not the same: you would still need ENTER to finish renaming, arrow key to move to the next file, and F2 to rename it. TAB does it in 1 step once you are renaming a file.
– MestreLion
Aug 30 '11 at 18:25
@MestreLion But it's very similar to algorithm described in the question and does not require neither any additional software nor command-line operations. Sort of being user-friendly.
– Rafał Cieślak
Aug 30 '11 at 19:31
True, you were the only answer that at least tried the same approach as the original question. And the sad truth is that Nautilus has no such functionality. You can F2 to rename, but thats it. No TAB to automatically jump you to next file in rename mode already.
– MestreLion
Aug 31 '11 at 5:18
add a comment |
It is not the same: you would still need ENTER to finish renaming, arrow key to move to the next file, and F2 to rename it. TAB does it in 1 step once you are renaming a file.
– MestreLion
Aug 30 '11 at 18:25
@MestreLion But it's very similar to algorithm described in the question and does not require neither any additional software nor command-line operations. Sort of being user-friendly.
– Rafał Cieślak
Aug 30 '11 at 19:31
True, you were the only answer that at least tried the same approach as the original question. And the sad truth is that Nautilus has no such functionality. You can F2 to rename, but thats it. No TAB to automatically jump you to next file in rename mode already.
– MestreLion
Aug 31 '11 at 5:18
It is not the same: you would still need ENTER to finish renaming, arrow key to move to the next file, and F2 to rename it. TAB does it in 1 step once you are renaming a file.
– MestreLion
Aug 30 '11 at 18:25
It is not the same: you would still need ENTER to finish renaming, arrow key to move to the next file, and F2 to rename it. TAB does it in 1 step once you are renaming a file.
– MestreLion
Aug 30 '11 at 18:25
@MestreLion But it's very similar to algorithm described in the question and does not require neither any additional software nor command-line operations. Sort of being user-friendly.
– Rafał Cieślak
Aug 30 '11 at 19:31
@MestreLion But it's very similar to algorithm described in the question and does not require neither any additional software nor command-line operations. Sort of being user-friendly.
– Rafał Cieślak
Aug 30 '11 at 19:31
True, you were the only answer that at least tried the same approach as the original question. And the sad truth is that Nautilus has no such functionality. You can F2 to rename, but thats it. No TAB to automatically jump you to next file in rename mode already.
– MestreLion
Aug 31 '11 at 5:18
True, you were the only answer that at least tried the same approach as the original question. And the sad truth is that Nautilus has no such functionality. You can F2 to rename, but thats it. No TAB to automatically jump you to next file in rename mode already.
– MestreLion
Aug 31 '11 at 5:18
add a comment |
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 recursively qmv -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/
I just tried this based on your suggestion. This is really the most awesome tool if you use vim!
– ste_kwr
Aug 14 '14 at 0:07
add a comment |
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 recursively qmv -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/
I just tried this based on your suggestion. This is really the most awesome tool if you use vim!
– ste_kwr
Aug 14 '14 at 0:07
add a comment |
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 recursively qmv -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/
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 recursively qmv -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/
edited Apr 13 '17 at 12:23
Community♦
1
1
answered Aug 30 '11 at 20:47
dempa
17913
17913
I just tried this based on your suggestion. This is really the most awesome tool if you use vim!
– ste_kwr
Aug 14 '14 at 0:07
add a comment |
I just tried this based on your suggestion. This is really the most awesome tool if you use vim!
– ste_kwr
Aug 14 '14 at 0:07
I just tried this based on your suggestion. This is really the most awesome tool if you use vim!
– ste_kwr
Aug 14 '14 at 0:07
I just tried this based on your suggestion. This is really the most awesome tool if you use vim!
– ste_kwr
Aug 14 '14 at 0:07
add a comment |
If the only suitable option is renaming the files manually, a great way to do that is using vidir
(in the moreutils
package):
sudo add-apt-repository universe && sudo apt-get update && sudo apt-get install moreutils
DESCRIPTION
vidir allows editing of the contents of a directory in a text editor.
If no directory is specified, the current directory is edited.
When editing a directory, each item in the directory will appear on
its own numbered line. These numbers are how vidir keeps track of what
items are changed. Delete lines to remove files from the directory, or
edit filenames to rename files. You can also switch pairs of numbers
to swap filenames.
Note that if "-" is specified as the directory to edit, it reads a
list of filenames from stdin and displays those for editing.
Alternatively, a list of files can be specified on the command line.
Examples
Renaming files selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Run vidir
, rename the filenames in the lines containing the filenames you wish to rename; hit CTRL+O and CTRL+X:
.
├── bar.bak
├── baz.old
└── foo.new
Switching filenames selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Current working directory's files' content:
$ for f in *; do printf '- %s:nn' "$f"; cat "$f"; echo; done
- bar:
This is bar
- baz:
This is baz
- foo:
This is foo
$
Run vidir
, switch the numbers in the lines containing the filenames you wish to switch; hit CTRL+O and CTRL+X:
.
├── bar
├── baz
└── foo
$ for f in *; do printf '- %s:nn' "$f"; cat "$f"; echo; done
- bar:
This is foo
- baz:
This is bar
- foo:
This is baz
$
Removing files selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Run vidir
, remove the lines containing the files you wish to delete; hit CTRL+O and CTRL+X:
.
└── baz
add a comment |
If the only suitable option is renaming the files manually, a great way to do that is using vidir
(in the moreutils
package):
sudo add-apt-repository universe && sudo apt-get update && sudo apt-get install moreutils
DESCRIPTION
vidir allows editing of the contents of a directory in a text editor.
If no directory is specified, the current directory is edited.
When editing a directory, each item in the directory will appear on
its own numbered line. These numbers are how vidir keeps track of what
items are changed. Delete lines to remove files from the directory, or
edit filenames to rename files. You can also switch pairs of numbers
to swap filenames.
Note that if "-" is specified as the directory to edit, it reads a
list of filenames from stdin and displays those for editing.
Alternatively, a list of files can be specified on the command line.
Examples
Renaming files selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Run vidir
, rename the filenames in the lines containing the filenames you wish to rename; hit CTRL+O and CTRL+X:
.
├── bar.bak
├── baz.old
└── foo.new
Switching filenames selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Current working directory's files' content:
$ for f in *; do printf '- %s:nn' "$f"; cat "$f"; echo; done
- bar:
This is bar
- baz:
This is baz
- foo:
This is foo
$
Run vidir
, switch the numbers in the lines containing the filenames you wish to switch; hit CTRL+O and CTRL+X:
.
├── bar
├── baz
└── foo
$ for f in *; do printf '- %s:nn' "$f"; cat "$f"; echo; done
- bar:
This is foo
- baz:
This is bar
- foo:
This is baz
$
Removing files selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Run vidir
, remove the lines containing the files you wish to delete; hit CTRL+O and CTRL+X:
.
└── baz
add a comment |
If the only suitable option is renaming the files manually, a great way to do that is using vidir
(in the moreutils
package):
sudo add-apt-repository universe && sudo apt-get update && sudo apt-get install moreutils
DESCRIPTION
vidir allows editing of the contents of a directory in a text editor.
If no directory is specified, the current directory is edited.
When editing a directory, each item in the directory will appear on
its own numbered line. These numbers are how vidir keeps track of what
items are changed. Delete lines to remove files from the directory, or
edit filenames to rename files. You can also switch pairs of numbers
to swap filenames.
Note that if "-" is specified as the directory to edit, it reads a
list of filenames from stdin and displays those for editing.
Alternatively, a list of files can be specified on the command line.
Examples
Renaming files selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Run vidir
, rename the filenames in the lines containing the filenames you wish to rename; hit CTRL+O and CTRL+X:
.
├── bar.bak
├── baz.old
└── foo.new
Switching filenames selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Current working directory's files' content:
$ for f in *; do printf '- %s:nn' "$f"; cat "$f"; echo; done
- bar:
This is bar
- baz:
This is baz
- foo:
This is foo
$
Run vidir
, switch the numbers in the lines containing the filenames you wish to switch; hit CTRL+O and CTRL+X:
.
├── bar
├── baz
└── foo
$ for f in *; do printf '- %s:nn' "$f"; cat "$f"; echo; done
- bar:
This is foo
- baz:
This is bar
- foo:
This is baz
$
Removing files selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Run vidir
, remove the lines containing the files you wish to delete; hit CTRL+O and CTRL+X:
.
└── baz
If the only suitable option is renaming the files manually, a great way to do that is using vidir
(in the moreutils
package):
sudo add-apt-repository universe && sudo apt-get update && sudo apt-get install moreutils
DESCRIPTION
vidir allows editing of the contents of a directory in a text editor.
If no directory is specified, the current directory is edited.
When editing a directory, each item in the directory will appear on
its own numbered line. These numbers are how vidir keeps track of what
items are changed. Delete lines to remove files from the directory, or
edit filenames to rename files. You can also switch pairs of numbers
to swap filenames.
Note that if "-" is specified as the directory to edit, it reads a
list of filenames from stdin and displays those for editing.
Alternatively, a list of files can be specified on the command line.
Examples
Renaming files selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Run vidir
, rename the filenames in the lines containing the filenames you wish to rename; hit CTRL+O and CTRL+X:
.
├── bar.bak
├── baz.old
└── foo.new
Switching filenames selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Current working directory's files' content:
$ for f in *; do printf '- %s:nn' "$f"; cat "$f"; echo; done
- bar:
This is bar
- baz:
This is baz
- foo:
This is foo
$
Run vidir
, switch the numbers in the lines containing the filenames you wish to switch; hit CTRL+O and CTRL+X:
.
├── bar
├── baz
└── foo
$ for f in *; do printf '- %s:nn' "$f"; cat "$f"; echo; done
- bar:
This is foo
- baz:
This is bar
- foo:
This is baz
$
Removing files selectively
Current working directory's content:
.
├── bar
├── baz
└── foo
Run vidir
, remove the lines containing the files you wish to delete; hit CTRL+O and CTRL+X:
.
└── baz
edited Feb 10 '16 at 10:34
answered Feb 10 '16 at 10:07
kos
25.3k870119
25.3k870119
add a comment |
add a comment |
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 with man rename
.
add a comment |
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 with man rename
.
add a comment |
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 with man rename
.
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 with man rename
.
edited Aug 25 '11 at 7:00
answered Aug 25 '11 at 6:49
Adobe
2,32932040
2,32932040
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f58546%2fhow-do-i-easily-rename-multiple-files-using-command-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Could you define "more control"? Not sure what you're asking exactly..
– Dang Khoa
Aug 25 '11 at 2:08
I think this question is not answered. What you are asking for (F2 and then jump in F2 mode to the next file) is currently not available I think in Nautilus.
– don.joey
Jul 16 '13 at 20:14