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 have a folder structure where withing a parent folder called D there are 100s folders each with a name like u0001, u0002 and so on. I have two other folders names qb and kc which are outside D. Within the qb and kc folders there are corresponding files like u0001.qb and u0001.kc and so on. I'm looking for some scipts that can copy the .qb and .kc files to the corresponding folders in D. So the u0001.qb and u0001.kc files will be copied from qb and kc folders to the u0001 folders.Is there anyway that the script runs everyday automatically to update the folders? If one could help me would be obliged. Just I've been trying to help a charity.
Pseudo code, since I don't know the exact structure of your
directory layout ...
Code:
for i in /path/to/kc/*kc
do
targetdir=$( basename ${i} .kc )
cp $i /path/to/${targetdir}/.
done
for i in /path/to/qb/*qb
do
targetdir=$( basename ${i} .qb )
cp $i /path/to/${targetdir}/.
done
Very kind of you for your code . I really appreciate this.Very kind of you.
The directory structure is as follows. If you please tell me where to put the path would be great!
There is a folder called D and within D there are folders with U0001,U00002......( there are 100s of folders)
There is another two folders in the same level as D called KC(contain u0001.kc, u00002 and so on) and QB (contain u0001.qb, U0002.qb and so on). So the folder D, QB and KC all are on the same level
I would like to run the script from the parent folder where is D, QB and KC exists.
In your code, please let me know where to add the path.
I really appreciate your help and would be obliged.
I'm a medic and hence I appreciate help from people like you.
The '/path/to' parts need to be replaced with your own full pathnames. Using full pathnames has the advantage that the script can run from any location (not just the parent folder), and that it also works correctly when launched by a cron job.
Very kind of you for your code . I really appreciate this.Very kind of you.
The directory structure is as follows. If you please tell me where to put the path would be great!
There is a folder called D and within D there are folders with U0001,U00002......( there are 100s of folders)
There is another two folders in the same level as D called KC(contain u0001.kc, u00002 and so on) and QB (contain u0001.qb, U0002.qb and so on). So the folder D, QB and KC all are on the same level
I would like to run the script from the parent folder where is D, QB and KC exists.
In your code, please let me know where to add the path.
I really appreciate your help and would be obliged.
I'm a medic and hence I appreciate help from people like you.
Try this (make a back-up first ;})
Code:
#!/bin/bash
for i in KC/*kc
do
temp=$(echo $( basename ${i} .kc ) | tr '[a-z]' '[A-Z]' )
target="D/${temp}/."
cp $i ${target}
done
for i in QB/*qb
do
temp=$(echo $( basename ${i} .qb ) | tr '[a-z]' '[A-Z]' )
target="D/${temp}/."
cp $i ${target}
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.