Reputation: 1
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.
Upvotes: 0
Views: 171
Reputation: 124648
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
Upvotes: 2