rename command and wild cards
Hi there, I am using hte rename command to clean up a bunch of files. I know you should be able to use regex with the rename command, but it seems to ignore them.
Most of the time I am using something like: rename 'something' 'some' * Now lets say I have files named: someFile(2009).ext otherFile(2008).ext File(2006).ext newFile(somthing).ext How could I strip away anything in brackets? To me something like this would make sense: rename '(*)' '' *.ext I just mostly want to know if there is a way to use a wild card... Thanks in advance. D |
Some body correct me if I'm wrong, but are parentheses considered valid characters in the context of a filename? Perhaps you could give us a better example of the before and after results you are trying to accomplish.
Regards, Fordeck |
Quote:
Let's say you're collecting some data from your system. You could, I suppose, create a file named: vmstat 10 8640 > statistics(20090827).data and if you want to be sure the shell doesn't do something unexpected with parentheses in the filename you could modify that command to be: vmstat 10 8640 > statistics\(20090827\).data Call me lazy but, personally, I think you're better off not creating filenames with special characters so you don't have to remember to escape them when manipulating the files. That goes for spaces in filenames, too. (Remember, the underscore is your friend.) Otherwise you end up having to do more work figuring out how to use those files. -- RT |
Command rename traits characters in from and to strings as-is. So * is asterisk not any string of characters. Compare these three examples:
$ touch left\*right $ ls Code:
left*right $ ls Code:
leftright $ ls Code:
lef*right $ ls Code:
File(2006).ext newFile(somthing).ext otherFile(2008).ext someFile(2009).ext $ ls Code:
File.ext newFile.ext otherFile.ext someFile.ext |
Why summon perl if sed does the same thing?
;} Code:
sed 's/\(.*\)//' |
For the best compatibility it's good to use only those characters in file's names:
A-Z a-z 0-9 _ - + . That character is hard coded in Linux kernel so it's impossible to use it in file's names: / Some characters are acceptable in Linux but impossible to use in Windows: * ? \ | : " I use in my MP3 collection file's names these additional characters: space ! # % & ' ( ) , ; = [ ] |
Quote:
$ ls Code:
File(2006).ext newFile(somthing).ext otherFile(2008).ext someFile(2009).ext Code:
mv: missing destination file operand after `File(2006).ext' Code:
File(2006).ext newFile(somthing).ext otherFile(2008).ext someFile(2009).ext |
You're right ... I was mixing sed's syntax for regex and
extended regex. It's even simpler. Code:
$ touch File\(2006\).ext newFile\(somthing\).ext otherFile\(2008\).ext someFile\(2009\).ext$ ls -ltr total 0 |
Quote:
That command doesn't work: for file in *.ext ; do mv $file `echo $file | sed "s/\(.*\)//"` ; done That command works: for file in *.ext ; do mv $file `echo $file | sed "s/(.*)//"` ; done |
All times are GMT -5. The time now is 07:08 AM. |