Rename all files to lowercase?

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

  1. Charles1718

    Charles1718 New Member

    Messages:
    3
    Likes Received:
    1
    Trophy Points:
    0
    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
    DevynCJohnson likes this.
  2. ehansen

    ehansen New Member Staff Writer

    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    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:
    ehansen@desktop:~# touch TESTING.txt
    ehansen@desktop:~# 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
    ehansen@desktop:~# 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
    ehansen@desktop:~# 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
    DevynCJohnson and Charles1718 like this.
  3. Charles1718

    Charles1718 New Member

    Messages:
    3
    Likes Received:
    1
    Trophy Points:
    0
    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 New Member

    Messages:
    87
    Likes Received:
    4
    Trophy Points:
    0
    Don't forget powerful linux command "rename".
    DevynCJohnson and Charles1718 like this.
  5. DarthVader3257

    DarthVader3257 New Member

    Messages:
    45
    Likes Received:
    2
    Trophy Points:
    0
    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.
    DevynCJohnson likes this.
  6. ehansen

    ehansen New Member Staff Writer

    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    I'm guessing you didn't actually read the thread all the way?
  7. ddd-222

    ddd-222 New Member

    Messages:
    3
    Likes Received:
    1
    Trophy Points:
    0
    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.
    DevynCJohnson likes this.
  8. humpty

    humpty New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    I tried this method before. It can't handle filenames with spaces in them.

Share This Page