You got two possibilities here regarding file linking: Symlinks
(soft links) and Hard Links
. This last one may be the one you need for your specific case.
Soft Links
These are just pointers to the original files, just as when you create a shortcut of a file/program in desktop while working on Windows, for example. If the original gets deleted, the symlink gets deleted too (or as in WS, just becomes useless).
Hard Links
These are clones of the original files, which also reflect the changes made on the original one. Same thing happens if changes are made on one of the hard links: the changes will be reflected on the original and also on all other hard links from the same origin. The hard links do not get deleted once the original file does, acting as support elements for backup operations.
Programmatically creating links
Example:
Path symlink = Paths.get("/home/jars/symlinkToJar.jar");
if (Files.exists(symlink))
Files.delete(symlink);
/*Soft link-Symlink*/
Files.createSymbolicLink(symlink, Paths.get("/opt/jars/yourJar.jar"));
This will first make sure the target file doesn't exist, and creates a symlink
in /home/jars/symlinkToJar.jar
that behaves as a soft link to the original file /jars/yourJar.jar
. This link contents are not equal to the original file's, as a Symlink
is just a pointer.
symlinkToJar.jar(2KB)* ----> yourJar.jar(20KB)
Hard links
are created by calling createLink
. These are not just pointers, but complete byte to byte clones.
Example:
Path link = Paths.get("/home/someGui/Desktop/linkToJar.jar");
if (Files.exists(link))
Files.delete(link);
/*Hard link*/
Files.createLink(link, Paths.get("/opt/jars/yourJar.jar"));
This will first make sure the target file doesn't exist, and creates a link
in /Desktop/linkToJar.jar
that behaves as a hard link to the original file opt/jars/yourJar.jar
.
This link is indeed a mirror copy, so every operation you could perform on the original one should also be possible on this one, as they are the same exact clone of each other.
linkToJar.jar(20KB)* <----> yourJar.jar(20KB)
I'd suggest creating not a Symlink
but instead a Hard Link
to your original file, as your commands may involve accessing the file content itself, or they may assume the given path is a file (and not a pointer).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…