Wouldn't it be great if the mv command had an option to leave a symbolic link in the file's original location?
Posted by cdokme@reddit | linux | View on Reddit | 20 comments
For example, running mv --create-link /tmp/file ~/ would move the actual file to ~/file, but leave a symlink at /tmp/file -> ~/file. What do you guys think?
I saw a proper implementation of this approach in Bash, but I think this behavior should be embed into the original mv command.
EvilVim@reddit
Sounds awfully confusing.
siodhe@reddit
That's pretty terrible description. It affects more than one entry, and doesn't actually move the file unless two different filesystems are involved.
EvilVim@reddit
First line from the man Pages:
Okay, sure, it can also rename files and a bunch more, but it's pretty clear in the basics: it moves a file. Perhaps not physically if you want to be pedantic but most people don't care.
siodhe@reddit
No. The file on disk doesn't move unless you invoke a cross-filesystem move. In the normal case within a single filesystem, mv only changes directory listing contents. A given file can have any number of different names simultaneously, scattered all over the filesystem's (singular) directories, or even multiple, equally valid names in the same directory (or several). To detach the file from the directory structure, all the names would need to be removed, unlinking the directories from the file itself - and the file will persist anyway, nameless, if any process on the local host still has it open.
aioeu@reddit
Using that logic, you shouldn't be able to use
mvto move files between filesystems. You could just usecpandrminstead.EvilVim@reddit
I never said that. You're reframing my point into something else but whatever.
neoh4x0r@reddit
We don't need to cram-in functionality that's already handled by other commands.
This is the main reason why each tool does only one job, to be able to use them as modular building blocks to make getting work done far easier and less complicated when compared to using monolithic/all-encompassing tools.
AudioHamsa@reddit
no
svadilfaris@reddit
mv "source" "destination" && ln -s "$(realpath "source")" "destination"
or simply write a shell script.
RefrigeratorWitch@reddit
Or a simple mvln alias.
srivasta@reddit
This is what aliases are for
yahbluez@reddit
The ZEN of doing things right, is to do one job, not a nightmare of options.
If one needs this feature just write a "two liner" shell script or create an alias.
krumpfwylg@reddit
Excerpt from https://en.wikipedia.org/wiki/Unix_philosophy
mvto move files, andlnto create linksaioeu@reddit
That's why
lsdoesn't have an option to sort its out. We usels | sortinstead. Right?SeriousPlankton2000@reddit
… and something to detect when a symbolic link would not point to the right location and abort everything before the file is moved. So not simply
mv foo bar && ln -s bar fooBut I think
lnshould do the task because it already does have a "backup" function and can do relative linking, it's a simple matter of adding a "backup strategy" that places the "backup" on the given target location.siodhe@reddit
This would be a weird addition to mv. Not as weird as as who -r but still pretty weird. A new command would make sense instead. Also, hardlinks can be a better option in some cases.
Patient_Sink@reddit
Yeah, and
cpalready has--linkto create hardlinks, so completely unnecessary to havemvdo the same thing.Novero95@reddit
You can always create an alias like
mvln /path/to/source /new/path -> mv /path/to/source /new/path && ln /new/path /path/to/sourcefaultydesign@reddit
mvmoves files, adding other things on top sounds like an unnecessary complicationThere’s
lnto make linksinotocracy@reddit
No. I'm using
mvto move a file, why would I want to leave a remnant? If I want a symlink to the new location I'llln.