Copying linked files, replacing directories in bash scripts?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Copying linked files, replacing directories in bash scripts?
I have a centrally located folder ($HOME$/my-libs) with all of my 'completed' sources. When I create a new project, I 'lndir' the appropriate source directories into the project folder so that all projects use up to date sources and I have the links there to show me the dependencies.
When I back up a version, I would like to either
1) be able to copy the project folder and have the original files (instead of the links) copied with the folder
2) create a shell script to see which source folders exist in the project folder, and then copy the folders from the central source directory. In case that was not clear:
Suppose there are folders 'ALGORITHM', 'ANALYSIS', and 'FILE' in the source folder. Then suppose there was a project 'APP' that needed 'ALGORITHM', so I would 'lndir' that folder into 'APP/ALGORITHM'. The ideal script would decide "this folder contains 'ALGORITHM', which is also a folder in the source directory, therefore I will replace that folder with the actual one from source directory." Is that possible?
Re: Copying linked files, replacing directories in bash scripts?
Quote:
Originally posted by ta0kira
1) be able to copy the project folder and have the original files (instead of the links) copied with the folder
1) is easy. cp -rL. the "-L" flag dereferences the symlinks, following them and copying the actual files.
Quote:
2) create a shell script to see which source folders exist in the project folder, and then copy the folders from the central source directory. In case that was not clear:
This seems to defeat the purpose of using lndir in the first place. But just use simple tests and above cp command.
if [ -d APPS/ALGORITHM ]; then
cp -rL /path/ALGORITHM /path/APP;
fi
But now you're left re-copying every time you change anything in ALGORITHM, not to mention the redundancy. man lndir and read what it says...
Thanks, that is what I was looking for. I figured out the second part yesterday. In the project folders I am leaving the links, but I back up the projects once in a while. When I back one up, I want a (then-current) copy of the actual sources so that the project can be distro'd or put on CD, and I can reproduce the app just from that backup. Thanks again.
ta0kira
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.