Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Could you propose a way to copy a list of files from one directory to another.

During copying the script should capitalize the first letter of the filename and lowercase all other letters.

share|improve this question
Are you asking for help, or are you asking me to write it for you? – Xyon Jan 11 '13 at 13:03
Maybe you should show us some code that proves you tried to solve it and couldn't. – BenjiWiebe Jan 11 '13 at 13:26

For your consideration:

for i in *;
    fletter=`echo $i| cut -b 1`;                 # FIRST LETTER
    rest=`echo $i | cut -b 2-`;                  # THE REST
    fletter=`echo $fletter | tr "[a-z]" "[A-Z]"`;# CAPITILIZE FIRST LETTER
    rest=`echo $rest | tr "[A-Z]" "[a-z]"`;      # LOWER CASE THE REST
    cp "$i" "/target/directory/$fletter$rest" ;  # COPY TO DESTINATION

Here, * will expand to the files in the current directory. If you want this to be restricted to files only, consider the following:

find . -type f -print0 | while IFS= read -r -d '' i; do
    # rest of the script
share|improve this answer
Why for i in $(ls) and not for i in *? – slhck Jan 11 '13 at 16:07
@slhck I used this form to allow him to figure it out how to extend the example into more appropriate : \ls -p | grep -v "/" to process only files - not directories. – mnmnc Jan 11 '13 at 20:13
That's a really bad way to process only files and not directories and I would recommend against it, for multiple reasons. See: — in your example you should also quote the variables in order to be able to handle files with spaces or globbing characters in their name. – slhck Jan 11 '13 at 20:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.