[Leaplist] howto change the name of every file in a directory
Aaron Morrison
ae4ko at amsat.org
Thu Oct 9 10:19:23 EDT 2008
Gary,
It's a simple bash loop. If you want to see what's going to happen,
run this form:
cd /path/to/my/dune/mp3s
echo * # this shows the filenames that the shell will expand
for x in * ; do
echo mv $x \[dune_3\]_$x # adding the echo command will show what
would be normally be executed
done
(Just add "echo" in front of the mv command).
You'll see on the screen what the command would look like in it's
expanded form.
There are a couple of things (known as expansions) going on here. The
first is known as "globbing" which is a form of pattern matching and
that is the "*" character in the for statement. The second is
variable substitution (the $x )
Here's what happens:
The bash shell expands the "*" glob into all of the filenames that
match the pattern. Each expansion (in this case filenames) get
assigned to a shell variable named "x". The statements between the do
and done keywords are then processed. Each statement will then get
it's variables expanded (in our code, we are referencing the variable
"x" by using the $x form) and the expanded line is then executed.
When the "for" statement runs out of arguments, the loop finishes.
simple, eh?
--am
On 09 Oct 2008, at 09:57, Gray Frost wrote:
> Richard,
> I like this method. Short and simple. Can you break it down for me?
>
> I think it is saying:
> For everything in this directory move the variable named file called
> $x to a new file name "dune_3 + $x" to give you dune_3$x. This
> actually places the "dune_3" in the front of every file.
>
> Is this a form of SED or AWK? Or is it just that simple where it
> just adds a "dune_3" to each file name in the for loop?
>
> On Thu, Oct 9, 2008 at 12:30 AM, Richard F. Ostrow Jr. <rich at warfaresdl.com
> > wrote:
> write this into your console:
>
> cd /path/to/my/dune/mp3s
> for x in * ; do
> mv $x \[dune_3\]_$x
> done
>
> and that's it
> <quote who="Mr. Brunkow">
> > to add something to the front of the name?
> >
> > I have the audio MP3 collection of the Dune line of books. I want
> to
> > burn a MP3 CD, but dune, dune messiah are in order by alphabetics,
> but
> > children of dune is not. i want to add [dune_3]_ to the front of
> all of
> > the children of dune mp3 files.
> > --
> > Raymond L. Brunkow
> > 5th Degree Black Belt
> > Chief Instructor and Owner
> > Sun State Martial Arts LLC.
> > (407) 786-2525
> > ssma at ssma.us
> > http://www.ssma.us
> >
> > --
> > This message has been scanned for viruses and
> > dangerous content by MailScanner, and is
> > believed to be clean.
> >
> > _______________________________________________
> > Leaplist mailing list
> > Leaplist at leap-cf.org
> > http://lists.leap-cf.org/mailman/listinfo/leaplist
> >
>
>
> --
> Life without passion is death in disguise
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
> _______________________________________________
> Leaplist mailing list
> Leaplist at leap-cf.org
> http://lists.leap-cf.org/mailman/listinfo/leaplist
>
>
>
> --
>
> Gray
>
> " Don't think you are, know you are."
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean. _______________________________________________
> Leaplist mailing list
> Leaplist at leap-cf.org
> http://lists.leap-cf.org/mailman/listinfo/leaplist
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.leap-cf.org/pipermail/leaplist/attachments/20081009/644d582b/attachment.html
More information about the Leaplist
mailing list