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.
I need a bash script wich will copy files from one location to another with saved folder structure and with timetamp preserved. Can anyone help me to do this? Ty!
If you want to preserve just the timestamps and not the permission bits or extended attributes, you can use "cp --preserve=timestamps" I have an alias "cpt" for that.
Ty for replies. I need to copy backups from linux partiton to windwos ntfs partition every day but to have timestamp preserved and to save directory structure. And its need to be automated.
Ty for replies. I need to copy backups from linux partiton to windwos ntfs partition every day but to have timestamp preserved and to save directory structure. And its need to be automated.
Please read the "Question Guidelines" link in my posting signature. We will be happy to HELP you with things, but we are NOT going to write your scripts for you. We understand what you WANT, but you have to show effort of your own. There are THOUSANDS of very easily found bash scripting guides that can get you going, and you've been given hints in this thread.
Post what you have written/done of your own, and tell us where you're stuck. And bear in mind that you have just now told us you're copying from Linux to Windows...there are SOME permissions you won't be able to preserve, since Windows knows nothing about them. One way to get around this is to use tar to create a file on Linux (which WILL preserve the attributes), then copy that file to Windows.
Please read the "Question Guidelines" link in my posting signature. We will be happy to HELP you with things, but we are NOT going to write your scripts for you. We understand what you WANT, but you have to show effort of your own. There are THOUSANDS of very easily found bash scripting guides that can get you going, and you've been given hints in this thread.
Post what you have written/done of your own, and tell us where you're stuck. And bear in mind that you have just now told us you're copying from Linux to Windows...there are SOME permissions you won't be able to preserve, since Windows knows nothing about them. One way to get around this is to use tar to create a file on Linux (which WILL preserve the attributes), then copy that file to Windows.
Sorry that i pissed u off it wasnt my purpose. So far ive mounted shared disk from windows in linux and gave right premissions to it. I can copy files and stuff and it works good. Im searching for a way to avoid the script. As i saw cp -pr copy files with timestamp preserved. Also rsync working fine with -av option. Why am i avoiding script - i dont know nothing about bash scripting. Ive started with some tutorials but its not going so good. So im trying to combine commands to copy already backuped files from /home/d/folder1 and /home/d/folder2 which are on linux hdd and to put it on external hdd wich is on win machine, for example in H:/folder3 with saved folder structure. If i found i way i can put that command in script and set it in crontab to work everyday. I know only how to run one command from script. And dont yell cuz im just a few days in linux world. And ty for helping me and again sorry that i pissed u off.
You have not pissed anyone off...merely telling you the LQ Rules and guidelines. On that subject, please also see the LQ Rules regarding text-speak (and not using it).
Quote:
So far ive mounted shared disk from windows in linux and gave right premissions to it. I can copy files and stuff and it works good. Im searching for a way to avoid the script. As i saw cp -pr copy files with timestamp preserved. Also rsync working fine with -av option. Why am i avoiding script - i dont know nothing about bash scripting. Ive started with some tutorials but its not going so good. So im trying to combine commands to copy already backuped files from /home/d/folder1 and /home/d/folder2 which are on linux hdd and to put it on external hdd wich is on win machine, for example in H:/folder3 with saved folder structure. If i found i way i can put that command in script and set it in crontab to work everyday. I know only how to run one command from script. And dont yell cuz im just a few days in linux world. And ty for helping me and again sorry that i pissed u off.
Again, no one is yelling, pissed etc. And until you actually START scripting, you will NEVER be any better at it than you are now. There is a link to bash scripting tutorial in my posting signature, and many thousands of others you can easily find. They all have examples and full explanations.
And a script is nothing BUT a list of "combined commands". If you know how to do this from the command-line now by typing things in, then congratulations...you've written your script. Put those lines in a file, make it executable (see the man page on the chmod command), and run it. You can either run it manually or by using cron to schedule it to run whenever you'd like. To schedule things, read the man page on the crontab command.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.