In aix unix how to copy files/dirs without overwritting the old files

Posted on 2012-08-29
Last Modified: 2012-09-11
I have 100 files/dirs in server A and 10 of those are in Server B. How can i copy over those 100 files/dirs without overwriting the 10 that already exist in Server B?

In essence need to copy just the 90 files/dirs of the 100 from server A to server B.
Question by:assistunix
    LVL 20

    Expert Comment

    use the -n switch to cp
    LVL 20

    Assisted Solution

    AIX should have it, if not try

    cp –help

    -n, –no-clobber do not overwrite an existing file (overrides a previous -i option)

    Alternatively,  you can use rsync

    rsync -r –ignore-existing bar/. foo/.
    LVL 68

    Expert Comment

    cp -i ... ...

    will ask before overwriting, giving the opportunity to say "No".

    If this is not an option "rsync" could be the tool of choice. It's available at
    LVL 20

    Expert Comment

    Just remembered something simple.

    You could use the yes command

    yes n | cp -R -h -i /dir1/* /dir2
    LVL 48

    Accepted Solution

    The requirement is to copy files over the network, so cp won't work unless it's a NFS mounted directory or similar.

    rsync is the best tool to use, eg:

    rsync -av -ignore-existing /some/dir user@serverB:/dest/dir

    Open in new window


    Author Comment

    Thank you all for your responses- I tried using rsync, however syntax seems to be wrong for it, as it gives an error. Could you assist.

    # rsync -av -ignore-existing /home/bin root@test:/home/bin

    rsync: Failed to exec -existing: No such file or directory (2)
    rsync error: error in IPC code (code 14) at pipe.c(84) [sender=3.0.6]
    rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Broken pipe (32)
    rsync error: error in IPC code (code 14) at io.c(1525) [sender=3.0.6]
    LVL 68

    Assisted Solution


    with two dashes!

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
    Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now