Rename all files to lowercase?

C

Charles1718

Guest
Hi People,

I'm currently trying to Rename all files with .txt to lowercase with this commands below

PHP:
for tup in find *.txt
do 
tup_file=$tup 
tow_file="echo $tup | tr [A-Z] [a-z]" 
mv $tup_file $tow_file 
done

But somehow I always get this error Message "mv 'a-z' is not a Directory" ?? :confused:

Thanks in Advance!
Charles
 


OP
E

ehansen

Guest
Hi People,

I'm currently trying to Rename all files with .txt to lowercase with this commands below

PHP:
for tup in find *.txt
do 
tup_file=$tup 
tow_file="echo $tup | tr [A-Z] [a-z]" 
mv $tup_file $tow_file 
done

But somehow I always get this error Message "mv 'a-z' is not a Directory" ?? :confused:

Thanks in Advance!
Charles
Here's a one-liner I wrote and tested:
Code:
for tup in `find . -iname *.txt`; do tup_file=$tup && tow_file=`echo "$tup" | tr [A-Z] [a-z]` && echo "$tup -> $tow_file" && mv $tup_file $tow_file; done

I've used the same code as you, but there were some subtle differences. Probably the biggest issue with your code is that you quoted the "echo..." code. Instead, you have to have it executed. Besides that, you missed the "execute command" part in the for loop as well. I hope this helps you!

Oh, and to show it works:
Code:
[email protected]:~# touch TESTING.txt
[email protected]:~# ls -liha
total 0 KB
22413323 drwxr-xr-x  2 ehansen ehansen 4.0K 2012-01-31 19:01 .
22413315 drwxr-xr-x 26 ehansen ehansen 4.0K 2012-01-31 15:36 ..
22414780 -rw-r--r--  1 ehansen ehansen       0 2012-01-31 18:59 TESTING.txt
[email protected]:~# for tup in `find . -iname *.txt`; do tup_file=$tup && tow_file=`echo "$tup" | tr [A-Z] [a-z]` && echo "$tup -> $tow_file" && mv $tup_file $tow_file; done
./TESTING.txt -> ./testing.txt
[email protected]:~# ls -liha
total 0 KB
22413323 drwxr-xr-x  2 ehansen ehansen 4.0K 2012-01-31 19:01 .
22413315 drwxr-xr-x 26 ehansen ehansen 4.0K 2012-01-31 15:36 ..
22414780 -rw-r--r--  1 ehansen ehansen       0 2012-01-31 18:59 testing.txt
 
OP
C

Charles1718

Guest
resolved

Thanks ehansen!

My issue is now resolved.

This one-liner Code works perfectly! :)

PHP:
for tup in `find . -iname *.txt`; do tup_file=$tup && tow_file=`echo "$tup" | tr [A-Z] [a-z]` && echo "$tup -> $tow_file" && mv $tup_file $tow_file; done

Thanks again,
Charles
 
OP
D

DarthVader3257

Guest
This can't be fixed without just simply renaming the file in all lowercase? That's interesting. I would think that this wouldn't be too hard to do. Good luck with fixing this, though.
 
OP
E

ehansen

Guest
This can't be fixed without just simply renaming the file in all lowercase? That's interesting. I would think that this wouldn't be too hard to do. Good luck with fixing this, though.

I'm guessing you didn't actually read the thread all the way?
 
OP
D

ddd-222

Guest
Hi People,

I'm currently trying to Rename all files with .txt to lowercase with this commands below

PHP:
for tup in find *.txt
do 
tup_file=$tup 
tow_file="echo $tup | tr [A-Z] [a-z]" 
mv $tup_file $tow_file 
done

But somehow I always get this error Message "mv 'a-z' is not a Directory" ?? :confused:

Thanks in Advance!
Charles

tow_file="echo $tup | tr [A-Z] [a-z]"
should instead be:
tow_file=`echo $tup | tr [A-Z] [a-z]`
OR:
tow_file=$(echo $tup | tr [A-Z] [a-z])



on a US keyboard the correct quote is in the upper right-hand corner.
 
OP
H

humpty

Guest
I tried this method before. It can't handle filenames with spaces in them.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online

No members online now.

Top