Results 1 to 9 of 9
Good day. I am attempting to use the tool 'rename "regex-rule" files '
I have a group of files zzzzfpa.00nnnnnnnnnnn where n is any number. So I would like to ...
- 12-29-2009 #1Just Joined!
- Join Date
- May 2008
- Posts
- 10
file rename
Good day. I am attempting to use the tool 'rename "regex-rule" files '
I have a group of files zzzzfpa.00nnnnnnnnnnn where n is any number. So I would like to get rid of the zzzz and leave the rest of the file name. Here is what I have tried rename -n 's/zzzz//' zzzzfpa*
it returns nothing but if I do an ls zzzzfpa* it returns the thousands of files I have to rename.
Thanks
Allen
- 12-29-2009 #2
Hint: you need to use the for command:
I leave it to you to work out the actual code. We don't solve homework problems here.Code:for name in zzzzfpa.nn* do (code to do what you want to each $name) done
"I'm just a little old lady; don't try to dazzle me with jargon!"
- 12-29-2009 #3Just Joined!
- Join Date
- May 2008
- Posts
- 10
Thanks actually the for loop is how I did solve the problem. But I am attempting to learn how to use the rename function. I thought that maybe the fpa. with a dot being a special character is what is causing me headaches but I have done what I know with regex to work around it and so far have not figured it out. GRR
for f in zzzz*; do mv $f ${f/zzzz/}; done
But I would think it would be a simple thing to do with rename such does not seem to be the case.
The examples I have seen only refer to replacing the last portion of the file. IE rename "s/ *//g" *.mp3
woould remove all of the spaces out of a .mp3 file name. So, I must have some learning to do here on regex's
Thanks
Allen
- 12-29-2009 #4Just Joined!
- Join Date
- May 2008
- Posts
- 10
hmm this could be a redhat bug, or it could be that rename does not really take a regex except from perl?
rename zzzzfpa. fpa. zzzzfpa*
works fine bit if I try to use the -n -v or -f switches or a regex it does not work at all
Thanks
Allen
- 12-30-2009 #5
I don't think you can use regular expressions directly on the command line. The rules for filename "globbing" are different. You would need to use a utility that understands regexps. You might be able to do it by echoing the filenames through sed and back-quoting the result. Have a look at the man page for sed. It's a very powerful utility.
"I'm just a little old lady; don't try to dazzle me with jargon!"
- 12-30-2009 #6Linux Guru
- Join Date
- Oct 2007
- Location
- Tucson AZ
- Posts
- 1,939
This worked for me in a test directory and seems like a pretty simple use of rename:But I would think it would be a simple thing to do with rename such does not seem to be the case.
rename zzzz "" zzzzfpa*
- 12-31-2009 #7Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
My take on this is that there is more than one rename command. If you are on:
then you would have access to:Code:OS, ker|rel, machine: Linux, 2.6.18-164.9.1.el5, i686 Distribution : CentOS release 5.4 (Final)
(CentOS is essentially RedHat without the support contract.)Code:SYNOPSIS rename from to file... DESCRIPTION rename will rename the specified files by replacing the first occur- rence of from in their name by to.
However, on a distribution of Linux such as:
you would have access to:Code:OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64 Distribution : Debian GNU/Linux 5.0
The rename and prename there seem to be the same, whereas rename.ul is:Code:mv (1) - move (rename) files prename (1) - renames multiple files rename (1) - renames multiple files rename.ul (1) - Rename files mmv (1) - move/copy/append/link multiple files by wildcard patterns mostly from man -k rename
which corresponds to the CentOS rename.Code:SYNOPSIS rename from to file... rename -V DESCRIPTION rename will rename the specified files by replacing the first occur- rence of from in their name by to.
The utility that understands perl regexes on Debian is:
I think Hazel was trying to guide you to use mv in a loop, which is basic method of renaming files. After that, the discussion seemed to be diverge into different utilities.Code:SYNOPSIS rename [ -v ] [ -n ] [ -f ] perlexpr [ files ] DESCRIPTION "rename" renames the filenames supplied according to the rule specified as the first argument. The perlexpr argument is a Perl expression ...
Most Linux distributions are the same, but differences occur, so it is best to specify what you are using, and to look at man pages on that distribution.
Best wishes ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 01-01-2010 #8
Well, thank you drl! On this forum you start off by trying to help someone and end up getting helped yourself. I'd never heard of rename before this; I just looked at the man page for it and it's a wonderful way of doing global edits on file names.
"I'm just a little old lady; don't try to dazzle me with jargon!"
- 01-01-2010 #9Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:for file in zzzzfpa.* do echo mv "$file" "${file#zzzz}" done


Reply With Quote