LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-07-2007, 03:37 PM   #1
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 316

Rep: Reputation: 30
cp -iu not working


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.
 
Old 07-07-2007, 05:02 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
The update option (-u) will do what you want on its own.

If you needed to copy only non-existant files you could use:

cp -i *.[ch] ../../mud/src < <(yes n)

If you don't like the noise then use:
cp -i *.[ch] ../../mud/src/ < <(yes n) 2>/dev/null

This also works with the mv command, and may be needed if the --reply option doesn't exist.

Last edited by jschiwal; 07-09-2007 at 07:20 PM. Reason: Removed the (! :)
 
Old 07-07-2007, 05:20 PM   #3
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 316

Original Poster
Rep: Reputation: 30
That still doesn't work. I want to copy file(s) to ../../mud/src/ only if the current file is newer. I tried
Code:
cp -i bleach.c ../../mud/src/ < <(! :)
but it still asked me to overwrite the file, even though the file wasn't newer.
 
Old 07-07-2007, 06:48 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
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.
 
Old 07-07-2007, 06:53 PM   #5
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 316

Original Poster
Rep: Reputation: 30
Okay well in that case, I don't want it to verify with me if the target file is newer. How would I do that?
 
Old 07-07-2007, 07:15 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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! ;-)

Last edited by colucix; 07-07-2007 at 07:17 PM.
 
Old 07-09-2007, 10:06 AM   #7
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 316

Original Poster
Rep: Reputation: 30
I know that. But I don't want that. I don't want to have to be prompted for every single file (and that's a lot of files for all .c and .h files)
 
Old 07-09-2007, 06:50 PM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
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.

Last edited by jschiwal; 07-09-2007 at 07:19 PM.
 
Old 07-10-2007, 01:34 PM   #9
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 316

Original Poster
Rep: Reputation: 30
Quote:
You will not be prompted at all.
But that's the problem. I wanted to be prompted. But not for files that are older.
 
Old 07-19-2007, 05:13 AM   #10
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 316

Original Poster
Rep: Reputation: 30
As it turns out, the -iu problem I'm having is a bug in coreutils.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu Feisty - Sound was working, but mysteriously stops working after reboot. woodsy934 Linux - Software 7 07-04-2011 07:39 PM
Fortemedia FM801 card not working under FC5 on Intel 845 but working with windows morningkiran Linux - Hardware 0 11-30-2006 08:57 AM
acpi nearly working IBM thinkpad R40e 2684HVG no Fn key working, throttling OK Emmanuel_uk Linux - Laptop and Netbook 2 05-31-2006 02:41 AM
F1 - F10 not working when F13 - F20 working in Linux haivinay Linux - General 0 09-20-2004 08:31 AM
cannot download files in mozilla -save dialog not working, galeon not working cmisip Linux - General 0 08-03-2003 04:25 PM


All times are GMT -5. The time now is 05:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration