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'm trying to do cp -iu *.[ch] ../../mud/src/ to move all *.h and *.c files to another directory, but only overwrite those that are older than my current directory (thus the use of u). But it doesn't seem to work.
In my current dir:
Quote:
2007-07-07 11:36 makeobjs.c
In the dir I will copy it to:
Quote:
2007-07-07 11:40 ../../mud/src/makeobjs.c
That one is newer. Therefor, it shouldn't copy it.
So I went ahead and did cp -iu makeobjs.c ../../mud/src/
But it gave me:
Quote:
cp: overwrite `../../mud/src/makeobjs.c'?
Am I doing something wrong? It shouldn't be overwriting the file.
The update option (-u) will do what you want on its own.
jschiwal was right! Have you verified that answering yes do actually copy the file? Probably the shell verify if there is another file with the same name and then verify if it is newer or not.
I mean that using the -i option the shell prompt you with the question "overwrite...?" but even if you answer yes, the -u option avoids the copying if the source file is older than the target file (as you expected). In other words a newer file is never overwritten if you use the -u option, even if the shell make you believe that it is going to do that! ;-)
If you use "cp -u *.h *.c ../../mud/src/", only files with newer timestamps will be copied. You could see which files are copied with "cp -ul *.h *.c ../../mud/src/".
You will not be prompted at all.
I should correct my previous post however. The < <(! part will work if you want to respond no. But not for the right reason. Use < <(yes n) if you want to reply no and < <(yes y) if you want to reply yes. You need to do this in place of the --reply= option which is being removed from the cp and mv commands.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.