Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need to copy many files in to many folders in once, for example I have files result_1 result_2 result_3 and want to copy them to directories 1 2 3 respectively, how can I do that, I have tried cp, echo and find syntax but did not work out.
Any idea?
for id in {1..3}; do
echo result_${id}
cp result_"${id}" "${id}"
done
Thank you, but I need to change the name of the files after I moved them to the directories from result_# to just result, is it possible with this code to do that?
They are over 50 files and dirs.
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,152
Rep:
Yes just rename them in the mv command see the man page and also have a look at the advanced bash scripting guide, renaming files as you move/copy them is pretty basic we aint going to do all the work for you, you have enogh info here to complete the script, if you get stuck on a particular bit then say so and we will point you in the right direction, what won't happen is getting a complete script written for you you have to do some of theis yourself.
I definitely know about renaming files, mv, cp and rename command, what I needed to rename all the files result_# to result in once, it is a big process what I do if I rename it individually that means I have to rename 5000 (50 x 100)times the files, I have tried find syntax which I find very strong but it didn't work with this case.
I surely try every thing and when things are not working out then I come to this forum.
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,152
Rep:
If you don't want to rename them as you go ( 5000 file moves is not dificult in BASH ), mv them athen use find with the -exec switch and rename to rename the files, but I would do it all from the mv in the script.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.