Console Command Examples: Difference between revisions

From Free Knowledge Base- The DUCK Project
Jump to navigation Jump to search
Created page with "Linux specific console command examples Examples from other pages included. References also included. This document is in the form of "what you want to do" and "how to do i..."
 
Line 12: Line 12:
  do                                  # uses the tr command to convert case
  do                                  # uses the tr command to convert case
   mv -i "$FILE" `echo "$FILE" | tr '[A-Z]' '[a-z]'` 2> /dev/null
   mv -i "$FILE" `echo "$FILE" | tr '[A-Z]' '[a-z]'` 2> /dev/null
  done  
  done
 
These may fail on unsupported file systems such as FAT32 with an error such as:
mv: 'IMAG0001.JPG' and 'imag0001.jpg' are the same file
./IMAG0004.JPG not renamed: ./imag0004.jpg already exists
In this case you will have to move when you change case and move back again.  Here we will change an uppercase file extension to a lowercase one under FAT32
rename 's/\.JPG$/\.jpeg/' *.JPG
rename 's/\.jpeg$/\.jpg/' *.jpeg
 
There are plenty of other ways to accomplish such tasks.


== Related Pages ==
== Related Pages ==

Revision as of 14:14, 2 October 2019

Linux specific console command examples

Examples from other pages included. References also included. This document is in the form of "what you want to do" and "how to do it" taken from our old Linux forum with questions from linux users.

change file case UPPERCASE to lowercase in the same directory

The easiest way is this simple command which uses rename:

rename 'y/A-Z/a-z/' *

Another example using tr:

for i in *; do mv $i `echo $i | tr [:upper:] [:lower:]`; done

Shell script example from the old Advanced Shell Operations page

for FILE in *                        # use mv -i to avoid overwriting files
do                                   # uses the tr command to convert case
  mv -i "$FILE" `echo "$FILE" | tr '[A-Z]' '[a-z]'` 2> /dev/null
done

These may fail on unsupported file systems such as FAT32 with an error such as:

mv: 'IMAG0001.JPG' and 'imag0001.jpg' are the same file
./IMAG0004.JPG not renamed: ./imag0004.jpg already exists

In this case you will have to move when you change case and move back again. Here we will change an uppercase file extension to a lowercase one under FAT32

rename 's/\.JPG$/\.jpeg/' *.JPG
rename 's/\.jpeg$/\.jpg/' *.jpeg

There are plenty of other ways to accomplish such tasks.

Related Pages

If what you're looking for isn't on this page, try some of these related pages: