[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: A quick Q: how do I command something in large amount





On Fri, Sep 16, 2011 at 12:27 AM, Axel Freyn <axel-freyn@gmx.de> wrote:
On Thu, Sep 15, 2011 at 10:07:16AM -0600, Aaron Toponce wrote:
> On Fri, Sep 16, 2011 at 12:03:40AM +0800, lina wrote:
> > mv *.txt  *.pdf
> >
> > can it be done * way?
> >
> > all the *.txt in current directory?
>
> Yes. Checkout the rename(1) command. It comes from Perl, and can be used
> for exactly that. Or, you could write a simple for-loop:
>
>     for FILE in *.txt; do mv $FILE.txt $FILE.pdf; done
>
> You have options.
Just some additional remarks:
a) the for-loop won't work, as "FILE" is expanded to the name including
  the .txt, so if you have a file "a.txt" this loop will execute
          mv a.txt.txt a.txt.pdf
  You need instead
    for FILE in *.txt; do mv $FILE `basename $FILE .txt`.pdf; done
  in order to remove the ".txt" from the variable "$FILE"

Seriously, I have problem testing this one,

the come out is like:

 (basename $FILE .txt.pdf

sorry I might be so sleepy, I will check another time,
 


b) for-loops in bash can be REALLY problematic, as soon as you have
  special characters in your filenames. Like for example spaces or
  new-lines or other control characters... OK, at least new lines are
  luckily very rare, but they can exist.
  So you should try e.g.
    for FILE in *.txt; do mv "$FILE" "`basename \"$FILE\" .txt`".pdf; done
  (this works at least with spaces in the filename...)

Thanks for your detained explaination.

Axel


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: [🔎] 20110915162728.GH2798@axel" target="_blank">http://lists.debian.org/[🔎] 20110915162728.GH2798@axel




--
Best Regards,

lina



Reply to: