Unix administration - comand cp and mv

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > April 2005 > comand cp and mv





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author comand cp and mv
blackdog

2005-04-07, 8:48 pm

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.

Barry Margolin

2005-04-07, 8:48 pm

In article <1112919832.716926.163690@o13g2000cwo.googlegroups.com>,
"blackdog" <cljlk@hotmail.com> 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 ***
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com