0

I could write mv as

mv()
{
   cp $1 $2
   rm $1
}

Therefore, in file transfers cp rm and mv could be equal, but there are dissimilarities.

How are the two options different?

Viesturs
  • 943
  • 3
  • 12
  • 16
  • mv only behaves that way when you are moving a file to a different filesystem. – jordanm Dec 29 '17 at 14:24
  • 1
    Using cp creates a new file - new inode, blocks reserved on disk for the physical file, copying the blocks of the old file to the new file, making a inode/name-pair in a directory. If you're using mv on the other hand - as long as it's within the same filesystem - all that is done is making an inode/name-pair in a directory and removing the old inode/name-pair. No new inode, no new blocks, no copying of data; because you continue to use the old inode and physical file. If it's moved to another filesystem though, a new inode will be created, blocks reserved and blocks moved.. – Baard Kopperud Dec 29 '17 at 15:05

0 Answers0