Command line- rename a series of files
Command line- rename a series of files
Using command line I want to be able to rename a quantity of files to remove
the words and characters;
[Letter]
.0 (dot zero)
Here's the file name-
Robert[Letter]_30.0N_2025.pdf
Here's what I want it to be renamed to;
Robert_30_N_2025.pdf
Any idea how to do it? It must be at command line.
the words and characters;
[Letter]
.0 (dot zero)
Here's the file name-
Robert[Letter]_30.0N_2025.pdf
Here's what I want it to be renamed to;
Robert_30_N_2025.pdf
Any idea how to do it? It must be at command line.
-
- Posts: 1614
- Joined: 2008-02-21 17:03
- Location: Finland
- Has thanked: 1 time
- Been thanked: 85 times
Re: Command line- rename a series of files
Good to learn to use Debian package utils.
If those can't do, there are sed and awk.
Code: Select all
arto@dell:~$ aptitude search rename
p arename - automatic audio file renaming tool
p autorenamer - program to rename files to make them
p caja-rename - Batch renaming extension for Caja
p golang-github-google-renamei - provides a way to atomically create o
p gprename - complete batch renamer for Linux
p ifrename - Rename network interfaces based on va
p krename - powerful batch renamer for KDE
p libdevel-caller-ignorenamesp - module for hiding namespaces from cal
p mp3rename - Rename mp3 files based on id3tags
p mrename - tool for easy and automatic renaming
p node-gulp-rename - gulp pulgin to rename files
i rename - Perl extension for renaming multiple
p rename-flac - CLI tool to rename FLAC files
p renameutils - Programs to make file renaming easier
arto@dell:~$
Re: Command line- rename a series of files
For the known characters, you can run rename.
For pattern matching unknown characters ([Letter]) will require regular expressions which I do not know off the top of my head.
Code: Select all
rename 's/\.0//g'
-
- Posts: 1614
- Joined: 2008-02-21 17:03
- Location: Finland
- Has thanked: 1 time
- Been thanked: 85 times
Re: Command line- rename a series of files
Code: Select all
rename 's/\[Letter\]//' Robert[Letter]_30.0N_2025.pdf
Re: Command line- rename a series of files
Have been using Krename but it's too complicated for a simple user like me.arzgi wrote: 2024-12-11 15:24 Good to learn to use Debian package utils.If those can't do, there are sed and awk.Code: Select all
arto@dell:~$ aptitude search rename p arename - automatic audio file renaming tool p autorenamer - program to rename files to make them p caja-rename - Batch renaming extension for Caja p golang-github-google-renamei - provides a way to atomically create o p gprename - complete batch renamer for Linux p ifrename - Rename network interfaces based on va p krename - powerful batch renamer for KDE p libdevel-caller-ignorenamesp - module for hiding namespaces from cal p mp3rename - Rename mp3 files based on id3tags p mrename - tool for easy and automatic renaming p node-gulp-rename - gulp pulgin to rename files i rename - Perl extension for renaming multiple p rename-flac - CLI tool to rename FLAC files p renameutils - Programs to make file renaming easier arto@dell:~$
That's why I need the code for the purpose above.
Re: Command line- rename a series of files
Ok. I used the -n for a test. That's a start. Here's what I tried and the result;arzgi wrote: 2024-12-11 16:06Special characters must be quoted off.Code: Select all
rename 's/\[Letter\]//' Robert[Letter]_30.0N_2025.pdf
$ rename -n 's/\[Letter\]//' Robert[Letter]_30.0N_2025.pdf
$rename(Robert[Letter]_30.0N_2025.pdf, Robert_30.0N_2025.pdf)
But, it doesn't remove the .0 (dot zero).
Any ideas?
Re: Command line- rename a series of files
I can do it in two passes (just remove the -n);
rename -n 's/\[Letter\]//' Robert[Letter]_30.0N_2025.pdf
Then...
rename -n 's/\.0//' Robert[Letter]_30.0N_2025.pdf
rename -n 's/\[Letter\]//' Robert[Letter]_30.0N_2025.pdf
Then...
rename -n 's/\.0//' Robert[Letter]_30.0N_2025.pdf
-
- Posts: 1614
- Joined: 2008-02-21 17:03
- Location: Finland
- Has thanked: 1 time
- Been thanked: 85 times
Re: Command line- rename a series of files
So, is it a problem? In bash scriprt you can put as many commands as you like. Note still that string is not the same after the first command. Do ls between.
And if it is a requrement, it can be done in one line, but before I would test it does what you are looking for.
And if it is a requrement, it can be done in one line, but before I would test it does what you are looking for.
Re: Command line- rename a series of files
The real problem is I have no idea what I'm doing. So, syntax, etc, are meaningless to me.arzgi wrote: 2024-12-11 17:35 So, is it a problem? In bash scriprt you can put as many commands as you like. Note still that string is not the same after the first command. Do ls between.
And if it is a requrement, it can be done in one line, but before I would test it does what you are looking for.
- sunrat
- Site admin
- Posts: 7451
- Joined: 2006-08-29 09:12
- Location: Melbourne, Australia
- Has thanked: 134 times
- Been thanked: 665 times
Re: Command line- rename a series of files
I find the Multi-Rename tool in DoubleCommander to be easier to use than KRename. Still won't be something which will work automatically without learning how to use it.PDA123 wrote: 2024-12-11 16:10 Have been using Krename but it's too complicated for a simple user like me.
That's why I need the code for the purpose above.
What you are asking is not easily done as a simple click and go function.
So far the offered solutions are good possibilities, sed and awk will indeed do what you want. But also only single commands have been suggested and to do it in bulk will require some simple scripting, maybe easiest with a for loop.
If syntax is meaningless to you, it will be hard to understand and achieve what you want. This is a fairly simple task, do a little research to try to get a basic understanding of the process.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ” Remember to BACKUP!
Those who have lost data
...and those who have not lost data YET ” Remember to BACKUP!
- dilberts_left_nut
- Administrator
- Posts: 5465
- Joined: 2009-10-05 07:54
- Location: enzed
- Has thanked: 21 times
- Been thanked: 93 times
Re: Command line- rename a series of files
'rename' with the right regex and a glob to select files.
Doing it in two passes makes the regex an order of magnitude simpler.
You have excellent examples above, plus search up some regex basics to add understanding.
Doing it in two passes makes the regex an order of magnitude simpler.
You have excellent examples above, plus search up some regex basics to add understanding.
AdrianTM wrote:There's no hacker in my grandma...
- kent_dorfman766
- Posts: 570
- Joined: 2022-12-16 06:34
- Location: socialist states of america
- Has thanked: 69 times
- Been thanked: 76 times
Re: Command line- rename a series of files
FWIW, the rename command is a PERL script so it uses PERL style REs, which are not 100% POSIX RE interchangeable.
-
- Posts: 1614
- Joined: 2008-02-21 17:03
- Location: Finland
- Has thanked: 1 time
- Been thanked: 85 times
Re: Command line- rename a series of files
rename has been around for guite a long time, easy to find examples from the net.PDA123 wrote: 2024-12-11 23:58 The real problem is I have no idea what I'm doing. So, syntax, etc, are meaningless to me.
But hardwire then:
Code: Select all
[arto@dell:~$ mkdir /tmp/ren
arto@dell:~$ cd /tmp/ren
arto@dell:/tmp/ren$ touch Robert[Letter]_30.0N_2025.pdf
arto@dell:/tmp/ren$ ls
'Robert[Letter]_30.0N_2025.pdf'
arto@dell:/tmp/ren$ rename 's/\.0//' Robert[Letter]_30.0N_2025.pdf
arto@dell:/tmp/ren$ ls
'Robert[Letter]_30N_2025.pdf'
arto@dell:/tmp/ren$ rename 's/\[Letter\]//' Robert[Letter]_30N_2025.pdf
arto@dell:/tmp/ren$ ls
Robert_30N_2025.pdf
arto@dell:/tmp/ren$
Re: Command line- rename a series of files
You can use a for loop with the rename or mv command in the terminal. Here’s a bash example:
bash
bash
Code: Select all
for file in *.pdf; do
newname=$(echo "$file" | sed 's/\[Letter\]//; s/\.0N/_N/');
mv "$file" "$newname";
done