Results 1 to 15 of 15
  1. #1
    Join Date
    Jun 2001

    cp -f doesn't work?

    I'd like to copy some files without getting the overwrite confirmation. I'm using Redhat Linux 7.2 and as far as I know the command should be "cp -f", but somehow it doesn't work. Am I missing something or it's a known bug???

  2. #2
    Join Date
    May 2001
    Dayton, Ohio
    Try: cp -Rf * ../

    Or whatever files to where ever
    -Mat Sumpter
    Director, Product Engagement
    Penton Media

  3. #3
    Join Date
    Feb 2002
    [email protected] [~]# cp --help
    Usage: cp [OPTION]... SOURCE DEST
    or: cp [OPTION]... SOURCE... DIRECTORY
    or: cp [OPTION]... --target-directory=DIRECTORY SOURCE...
    Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

    -a, --archive same as -dpR
    --backup[=CONTROL] make a backup of each existing destination file
    -b like --backup but does not accept an argument
    -d, --no-dereference never follow symbolic links
    -f, --force if an existing destination file cannot be
    opened, remove it and try again
    -i, --interactive prompt before overwrite
    -H follow command-line symbolic links
    -l, --link link files instead of copying
    -L, --dereference always follow symbolic links
    -p, --preserve preserve file attributes if possible
    --parents append source path to DIRECTORY
    -P same as `--parents' for now; soon to change to
    `--no-dereference' to conform to POSIX
    -r copy recursively, non-directories as files
    WARNING: use -R instead when you might copy
    special files like FIFOs or /dev/zero
    --remove-destination remove each existing destination file before
    attempting to open it (contrast with --force)
    --sparse=WHEN control creation of sparse files
    -R, --recursive copy directories recursively
    --strip-trailing-slashes remove any trailing slashes from each SOURCE
    -s, --symbolic-link make symbolic links instead of copying
    -S, --suffix=SUFFIX override the usual backup suffix
    --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
    -u, --update copy only when the SOURCE file is newer
    than the destination file or when the
    destination file is missing
    -v, --verbose explain what is being done
    -x, --one-file-system stay on this file system
    --help display this help and exit
    --version output version information and exit

    I'd say try --force and --remove-destination, but don't take my word for it, I don't want to get sued.

  4. #4
    Join Date
    Jun 2001
    Thanks, I've tried "cp -Rf", "cp --force", and "cp --remove-destination" with no luck. It still gives me the overwrite confirmation message.

    Any other idea? Or maybe is there any other command to copy files (without getting overwrite confirmation) in Redhat Linux 7.2?

  5. #5
    The attributes of the files in your destination directory may have been altered from default or have special flags assigned to them.

    "lsattr" in the directory you are copying to. If files are flagged with i, you won't be able to overwrite them forcing a confirmation text to appear.

    Moreover, "cp -f files destination" should work fine under RH 7.2

  6. #6
    Join Date
    Jun 2001
    I ran "lsattr" in the destination directory and it returned "-------------" for all the files there. What does this mean?

  7. #7
    This would mean that none of the files in the destination directory have had their attributes altered.

  8. #8
    Join Date
    Jul 2001
    /bin/cp -f
    root has "alias cp cp -i" by default.

  9. #9
    Join Date
    Dec 2001
    Franklin, TN, USA
    Yeah, use /bin/cp -f, I asked just the same question a while ago
    Linux. Problems Solved. | Built for the Hosting Industry
    Server Management. Helpdesk Management. Business Management.
    ( AcuNett, Est. 15 Years, RateLobby 5 Stars )

  10. #10
    Join Date
    Jul 2001
    Originally posted by AcuNett
    Yeah, use /bin/cp -f, I asked just the same question a while ago
    and i answered the same thing.. twice in fact.. in the thread

  11. #11
    Join Date
    Jun 2001
    Thanks, "/bin/cp -f" works just great!

  12. #12
    Join Date
    Apr 2002
    Still strange, even if cp has an alias to cp -i, the -f option should override the -i.
    Fire extinguisher extraordinare
    FastServers.Net NOC Admin

  13. #13
    Join Date
    Jun 2001
    Yeah, you're right. I think it's probably a bug in Redhat Linux.

  14. #14
    Join Date
    Jul 2001
    No it's not a "bug" per se.

    It's just being safe. If you tell it to "ask before overwrite" (-i) and tell it to "just freaking overwrite" (-f), it determines you are crazy and just prompts you.

    [[email protected] test]$ cp -i -f 102.html bk
    cp: overwrite `bk/102.html'? y

  15. #15
    I know this post is pretty old... but I would like ot make thing clear to every one.

    the -f (force) option in cp has nothing to do with user interaction.
    this option will overwrite files even if they are write protected by deleting them before copy. This is possible because deleting and creating a a file is managed by the folder's rights whereas modifying a file is manage with the files right.

Posting Permissions

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