mv'ing files from a C program

Guy Harris guy at auspex.auspex.com
Mon Nov 26 09:27:52 AEST 1990


>Isn't invoking a shell a bit much to mv a file when you can
>link(2)/unlink(2)?  

In this particular case, it probably is.  The original poster seemed to
be indicating that they wanted to move a file (i.e., not a directory),
and may have wanted to move it to another directory on the same file
system.

If they'd wanted to move a directory, then unless their system had
"rename(2)" (in which case, using "link(2)" and "unlink(2)" is a bit
much) or their program was running as super-user, they'd almost
certainly have to run "mv", as most UNIX systems disallow anybody but
the super-user from linking to or unlinking from a directory.  (And even
if it *is* running as super-user, I'd still be tempted to run "mv"
anyway, as there's more than just a simple "link()/"unlink()" pair
involved in moving a directory.)

Also, if they wanted to move it to another file system, running "mv" may
be more convenient than duplicating "mv"s "try to move it with
'remove()' or 'link()/unlink()' and, if you get EXDEV, copy it" action.



More information about the Comp.unix.questions mailing list