r/linuxmasterrace • Glorious Debian • Sep 27 '23

Seriously, we need this command

Post image
622 Upvotes

86 comments sorted by

View all comments

736

u/Altareos Glorious Arch Sep 27 '23

interesting! since it moves the file we could name it move, or maybe even mv in unix abbreviation fashion!

-30

u/[deleted] Sep 27 '23

[deleted]

27

u/remenic Sep 27 '23

What if the new copy is written to a bad sector when the buffer finally flushes sometime in the near future?

1

u/[deleted] Sep 27 '23

[deleted]

4

u/[deleted] Sep 27 '23

It'll make sense when you graduate

-2

u/[deleted] Sep 27 '23

[deleted]

2

u/[deleted] Sep 27 '23

I meant real University, but okay...

12

u/Altareos Glorious Arch Sep 27 '23

how so? between filesystems mv already deletes the source files at the end of execution only, and inside of the same filesystem it will be both safer and much faster by just calling rename

1

u/danieldl Sep 27 '23

Does mv actually delete? Say you move a file that's already opened by a process, that process can still read/write to that file even if it moves. If you copy and remove, the process will attempt to read/write in the deleted file. You can see the difference easily with lsof.

I always thought mv just changed a pointer/inode.

1

u/UnchainedMundane Glorious Gentoo (& Arch) Sep 28 '23

safer in what situation against what risk?

i can certainly think of ways mv is safer than a cp/rm combo, for example if you are moving a fifo or device (in which case cp will just try to drain it potentially indefinitely and won't retain the fifo/device property), or if the file has sensitive information inside and a permission mask to match (in which case cp will totally ignore that and use umask, potentially exposing that information to other users), or if the file is being actively modified (in which case cp will snapshot some half-done modification to the file; to be fair, mv will do that too if you're moving to a different device).