View previous topic :: View next topic |
Author |
Message |
helmers Guru
Joined: 16 Sep 2002 Posts: 553 Location: Stange, Norway
|
Posted: Wed Oct 23, 2002 12:36 pm Post subject: Renaming groups of files from the command prompt |
|
|
One of the features don't know how to use, which I used a lot in Windows, is renaming files like this: "move *.wav *.mp3", and it would automagically understand it. Somehow I can't figure out how to do this
--
Regards,
Jan Henrik Helmers |
|
Back to top |
|
|
dippen Tux's lil' helper
Joined: 15 Sep 2002 Posts: 83
|
Posted: Wed Oct 23, 2002 12:41 pm Post subject: |
|
|
its allmost the same
(without dots)
look at for more information |
|
Back to top |
|
|
helmers Guru
Joined: 16 Sep 2002 Posts: 553 Location: Stange, Norway
|
Posted: Wed Oct 23, 2002 12:47 pm Post subject: |
|
|
Okay, to make it a bit tougher, what if the files contain these letters? Any more "solid" way?
--
Regards,
Helmers |
|
Back to top |
|
|
progster Apprentice
Joined: 16 Jul 2002 Posts: 271
|
Posted: Wed Oct 23, 2002 1:05 pm Post subject: |
|
|
then dippens way will work as well since manwavis does not equal *wav
~Progster |
|
Back to top |
|
|
helmers Guru
Joined: 16 Sep 2002 Posts: 553 Location: Stange, Norway
|
Posted: Wed Oct 23, 2002 2:39 pm Post subject: |
|
|
Great! Feel a bit dumb though, this have been bothering me for over a year. Guess you don't have to be smart to use 'nix
Thanks a lot for helping out!
--
Regards,
Helmers |
|
Back to top |
|
|
n0n Guru
Joined: 13 Jun 2002 Posts: 355
|
Posted: Wed Oct 23, 2002 4:03 pm Post subject: |
|
|
dippen wrote: | its allmost the same
(without dots) |
Um, this shouldn't actually work. And it certainly doesn't for me. When I need to rename files like that, I typically do:
Code: | for file in *.wav; do mv $file `basename $file .wav`.mp3; done |
Note that's bash syntax, other shells' mileage may vary.
Also, I'm sure you're probably aware of this, but simply changing the extension of a .wav file to .mp3 will not create an mp3 file for you. You'll need to invoke an actual mp3 encoder to create an mp3 file. |
|
Back to top |
|
|
phong Bodhisattva
Joined: 16 Jul 2002 Posts: 778 Location: Michigan - 15 & Ryan
|
Posted: Wed Oct 23, 2002 6:56 pm Post subject: |
|
|
The fundamental difference here is that in IIRC dos/windows the parameters are passed to programs more or less as typed. In *nix they are expanded by the shell BEFORE passing. In this case, if you had 3 wav files in the current directory (a.wav, b.wav and c.wav), the program would recieve the exact list of wav files as its parameters. Since there are no .mp3 files, that part gets expanded to nothing. The rule for mv is if you're moving multiple files, the last parameter (the target) must be a directory, since it makes no sense to move lots of files to one target filename. In windows/dos the wildcards are interpreted by the ren command so it can say "Oh, they said *.wav and *.mp3, they want to change everything that has an extension of .wav to be .mp3 instead".
The tradeoff is that in *nix you can do the "for" loop on the command line as mentioned by n0n. _________________ "An empty head is not really empty; it is stuffed with rubbish. Hence the difficulty of forcing anything into an empty head."
-- Eric Hoffer |
|
Back to top |
|
|
pjp Administrator
Joined: 16 Apr 2002 Posts: 20067
|
Posted: Wed Oct 23, 2002 9:37 pm Post subject: |
|
|
phong wrote: | they want to change everything that has an extension of .wav to be .mp3 instead". |
Quote: | in *nix you can do the "for" loop on the command line | Those two don't necessarily seem like they should be mutually exclusive. _________________ Quis separabit? Quo animo? |
|
Back to top |
|
|
n0n Guru
Joined: 13 Jun 2002 Posts: 355
|
Posted: Wed Oct 23, 2002 9:58 pm Post subject: |
|
|
kanuslupus wrote: | Those two don't necessarily seem like they should be mutually exclusive. |
Sure, not necessarily, but the behavior of the "mv" command has been very well defined. If you run this from the command line: mv will attempt to move the file named literally "*.wav" to a new file named (literally) "*.mp3." Expanding based off of a GLOB, at least in the UNIX world, belongs to the shell, and as such, the mv command can't be expected to do it's own expansions. Now, would it be too difficult to make your own "mv" that understands these things? Here, let's call it "bmv" for "bulk mv":
Code: | #!/bin/bash
# Run as: bmv wav mp3
foreach file in *.$1
do
mv $file `basename $file $1`.$2
done |
I didn't test that out at all, but it should basically be fine. Save it in your path and you're good to go . . . But the "mv" command itself shouldn't be responsible for those expansions. |
|
Back to top |
|
|
pjp Administrator
Joined: 16 Apr 2002 Posts: 20067
|
Posted: Wed Oct 23, 2002 10:27 pm Post subject: |
|
|
n0n wrote: | Expanding based off of a GLOB, at least in the UNIX world, belongs to the shell | I hadn't considered that... good point.
Quote: | I didn't test that out at all, but it should basically be fine. | I don't think it will handle spaces in file names, but I haven't tested it either. _________________ Quis separabit? Quo animo? |
|
Back to top |
|
|
gauched n00b
Joined: 12 Jul 2002 Posts: 6 Location: SLC, Utah
|
Posted: Fri Oct 25, 2002 5:20 pm Post subject: |
|
|
Globbing can have strange effects for someone who is more familiar with the dos world. I had alot of problems with accidently moving all of my /etc/* files into /etc/X11 because I expected a doslike behavior.
To address the original question, "emerge rename" should help you do what you want to do. |
|
Back to top |
|
|
pjp Administrator
Joined: 16 Apr 2002 Posts: 20067
|
Posted: Fri Oct 25, 2002 5:36 pm Post subject: |
|
|
A brief explanation of rename, as it is not initially obvious. See man for other nifty things you can do.
rename files with extension of .dat to .data (including filenames with spaces).
rename <from> <to> <files to change>
rename .dat .data *.dat _________________ Quis separabit? Quo animo? |
|
Back to top |
|
|
ryan83vt Guru
Joined: 28 Oct 2002 Posts: 370 Location: Blacksburg, VA
|
Posted: Thu Jan 30, 2003 8:30 pm Post subject: |
|
|
kanuslupus wrote: | A brief explanation of rename, as it is not initially obvious. See man for other nifty things you can do.
rename files with extension of .dat to .data (including filenames with spaces).
rename <from> <to> <files to change>
rename .dat .data *.dat |
can I do the same with some variant of the copy command? |
|
Back to top |
|
|
Donovan Tux's lil' helper
Joined: 08 Feb 2003 Posts: 97 Location: Halifax, NS, Canada
|
Posted: Sat Jun 14, 2003 4:51 pm Post subject: |
|
|
'rename' is no longer a separate package in portage. However, it is installed on my system, it must be included in some other package, perhaps baseutils or something.
If you really want to mass rename, check out krename... The version in portage is outdated at moment, I filed a report - see https://bugs.gentoo.org/show_bug.cgi?id=22826 to emerge the newest version as of this writing...
I would say there is no limit to what you can do with that krename... you can extract attributes from the files (photo details, mp3 details) and add them as part of the file name! _________________ Gentoo Linux * DirecTivo * Who needs heaven? |
|
Back to top |
|
|
far Guru
Joined: 10 Mar 2003 Posts: 394 Location: Stockholm, Sweden
|
Posted: Sat Jun 14, 2003 5:01 pm Post subject: |
|
|
Donovan wrote: | 'rename' is no longer a separate package in portage. However, it is installed on my system, it must be included in some other package, perhaps baseutils or something. |
Code: | prompt> qpkg -f `which rename`
sys-apps/util-linux * |
_________________ The Porthole Portage Frontend |
|
Back to top |
|
|
|