Find the answer to your Linux question:
Results 1 to 5 of 5
Hi all I need to copy a folder and its contents, automatically overwriting the existing folder if it exists. I can get the folder to copy e.g: cp -r /a/b/ ...
  1. #1
    Just Joined!
    Join Date
    Sep 2008
    Posts
    10

    copy folder contents without overwrite prompt

    Hi all

    I need to copy a folder and its contents, automatically overwriting the existing folder if it exists.

    I can get the folder to copy e.g:
    cp -r /a/b/ /c/

    but the second time i run the command it asks for confirmation:

    [root@SK-DB-CA-T /]# cp -r /c/b/ /a/
    cp: overwrite `/a/b/aaa.txt'? n
    cp: overwrite `/a/b/aaa.txt~'? n

    how do i stop it from doing so?

  2. #2
    Just Joined!
    Join Date
    Oct 2008
    Posts
    21
    use
    cp -Rf /c/b /a/

  3. #3
    Just Joined!
    Join Date
    Sep 2008
    Posts
    10
    Hi
    nope it does not work

    [root@SK-DB-CA-T /]# cp -Rf /c/b /a/
    cp: overwrite `/a/b/aaa.txt'? n
    cp: overwrite `/a/b/aaa.txt~'? n

    and i am using a stock standard red hat 5 installation, if that matters

  4. #4
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Feed it using the "yes" command.

    Code:
    yes | cp <whatever>
    If confirmation is needed, "yes" will be assumed as the answer and cp will continue.

  5. #5
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Maybe Red Hat has `cp -i` as a default option to ls?

    You can probably see by typing
    Code:
    echo $LS_OPTIONS
    What happens when you do /bin/ls -r dir blabla, does that do it non-interactively?
    Can't tell an OS by it's GUI

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...