Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd please sign up again. Thanks!

Rename all files to lowercase?

Discussion in 'Command Line' started by Charles1718, Jan 31, 2012.

  1. Charles1718

    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
     
    1 person likes this.
  2. ehansen

    ehansen Guest

    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
     
    2 people like this.
  3. Charles1718

    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_filedone
    Thanks again,
    Charles
     
  4. carbon333

    carbon333 Guest

    Don't forget powerful linux command "rename".
     
    2 people like this.
  5. 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.
     
    1 person likes this.
  6. ehansen

    ehansen Guest

    I'm guessing you didn't actually read the thread all the way?
     
  7. ddd-222

    ddd-222 Guest

    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.
     
    1 person likes this.
  8. humpty

    humpty Guest

    I tried this method before. It can't handle filenames with spaces in them.
     

Share This Page