comand cp and mv - Unix

This is a discussion on comand cp and mv - Unix ; I have an application which is written in C. The application contains command cp to copy a file to another file name, then use command rm to delete the original file. Some people think that is better then using command ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: comand cp and mv

  1. comand cp and mv

    I have an application which is written in C. The application contains
    command cp to copy a file to another file name, then use
    command rm to delete the original file. Some people think that is
    better then using command mv in a C program to rename a file because
    the mv command dose not always work in a C program, it get hung
    sometime.
    Would anyone please explain why and why not?

    Thanks.


  2. Re: comand cp and mv

    In article <1112919832.716926.163690@o13g2000cwo.googlegroups. com>,
    "blackdog" wrote:

    > I have an application which is written in C. The application contains
    > command cp to copy a file to another file name, then use
    > command rm to delete the original file. Some people think that is
    > better then using command mv in a C program to rename a file because
    > the mv command dose not always work in a C program, it get hung
    > sometime.
    > Would anyone please explain why and why not?


    The mv command will use rename() if the source and destination are on
    the same filesystem, which is *much* better.

    If they're on different filesystems, mv works like cp followed by rm.
    If cp succeeds, so should mv. You should probably use the -f option to
    prevent mv from asking questions.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***

+ Reply to Thread