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.
Hi everybody. I'm looking into some cron'd .sh scripts on one of my servers, but had a real basic question to help me try to understand this mess i have.
If there is a cp or mv in a script, but the destination file already exists with the same name, by default does it overwrite, or will that fail to copy the new/updated file with the same name because 1 exists already?
Why don't you try it and see? Create a couple of dummy files, write a short script to overwrite one with the other, and see what happens. That way, you teach yourself, more satisfactory than being taught.
The default behavior for mv and cp is to overwrite the existing files. You can use the options -b or --backup with those commands, in that case the commands will make a backup file (usually with the ~ suffix, but you can specify that when using the --backup option) of the already existing file before overwriting it.
For more info have a look at
So I wouldn't need to throw a -f in there to force a .sh to overwrite the destination files with the same names that i'm trying to copy and move over? it would do it by default?
The -f option only applies when the already existent file can't be opened for whatever reason. That normally shouldn't happen, so -f shouldn't be needed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.