0

I need your help in writing a script(ubuntu-bash). suppose i have a folder in a certain name and i want to copy all the files in the folder to a sub-folder that starts with the first letter of the file. for instance, a file named alaska will be copied to folder "A", the file named colorado will be cppied to folder "C" and so on. of course it will include files with lowercase and uppercase letters and a folder with one uppercase letter.

thanks.

1
  • 1
    Hi and welcome to SO. Please review the FAQ. We try to answer specific programming questions and this is a bit too broad and doesn't contain enough information to give a specific answer. Commented Dec 7, 2013 at 22:52

1 Answer 1

2

I hope you can build on this example:

for f in file1 file2; do
    dir=$(echo ${f:0:1} | tr a-z A-Z)
    mkdir -p $dir
    cp -v "$f" $dir
done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.