Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
4  
Are you asking for help, or are you asking me to write it for you? –  Xyon Jan 11 '13 at 13:03
2  
Maybe you should show us some code that proves you tried to solve it and couldn't. –  BenjiWiebe Jan 11 '13 at 13:26

1 Answer 1

For your consideration:

for i in *;
do
    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
done

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
done
share|improve this answer
3  
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
2  
That's a really bad way to process only files and not directories and I would recommend against it, for multiple reasons. See: mywiki.wooledge.org/BashFAQ/020 — 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

 
discard

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.