INTRODUCTION (Feel free to skip)
So I’ve been putting a lot more work into my Plex library under Pandemic isolation, & I’ve started cleaning things up, trying to remove duplicates & I realized I have a bunch of stuff in two places. For me it’s mostly things like Christmas movies that are part of a series that I have 2 copies of the file, 1 as a movie, & another as an episode of the show. So last night I decided to get rid of the duplicates by replacing them with
Hard Links. & I went to search the forums to see if anyone had anytipsorbest practicesforHard Linksor if there was any reason to useSymbolic Linksinstead. I was surprised to note that none existed except some issues withSymbolic Linksso I decided to start a thread, share my practices, & hopefully help others as well as encourage anyone with different methods to suggest them. So on that note let’s begin
NOTE: While I am usingWindows 10& all the methods outlined are using Windows 10, the same methods should work on all NTFS drives inWindows 7,Windows 8, & evenVista&XP.
ALSO NOTE: These practices should also work inLinux&Unix(Including Mac) systems, but will require knowledge of theHard Linkcommands for those operating systems.
- So 1ˢᵗ, I chose to use
Hard Links& I believe they work better unless you are doing 1 of the following
- Linking to a different drive or partition or to a network location
- Like things breaking on you
- 2ⁿᵈ I’m well accustomed to using
Hard Links
So lets go over a couple requirements before we begin
- You must be using NTFS (HFS on Mac or EXT4/EXT3/EXT2 on Linux)
- Your location has to exist on the same file structure table, both will be essentially pointing to the same spot on the disk so they both have to be able to see that spot. I get more into that in a bit.
Now to dispel some concerns you might have
- Both files do NOT need to have the same name
- After being created the files CAN be moved or renamed without worrying about breaking the link
- Deleting 1 does NOT delete the other. The file will continue to exist until ALL links are deleted
- If you edit a
Hard Linked file those edits will be reflected on all versions - There is no risk of
Infinite LoopsfromHard Linked files, Infinite loops can only occur when I directory nests within a parent to itself. AsHard Linksare not relative pointers that cannot happen. Plus, sinceHard Linksare limited to files & not possible for folders at all this issue can never occur. TheLink Shell Extensiondoes give the ability to createJunctionswhich could lead to that problem if used carelessly.Junctions, likeSymbolic Linksare relative links to folder, used natively within Windows & other Operating Systems so that common files can exist across profiles without taking extra disk space.
ABOUT HARD LINKS: What Are They? How Do They Work? (Feel free to skip)
A
Hard Linkis often referred to as being like a shortcut, but it actually has absolutely no similarities to a shortcut. EveryHard Linkis the actual file. Here’s how it works. When you create a file in the directory P:\Files\MyMovie.mkv nothing actually exists in any folder, folders are illusions. that file is known to the Drive by anInodewhich is like it’s ID Tag. When you create that file anInodeis created for it telling the File System which blocks of the disk contain the information for that file. Lets say your file’sInodeis1234abcDEin the File System you have a table telling it to showInode 1234abcDEin the DirectoryP:\Files\under the nameMyMovie.mkv. When you move the file to DirectoryP:\Archive\When I Was Young\nothing is actually moved on the disk, the information on the table for theInode 1234abcDEas just been updated. If you make a copy of the file a newInode, lets say34dS87LLgis created & though the files may be identical, they are separate files.
So when you create aHard Linkyou are just adding a 2nd Entry to thatInode. This is different from aSymbolic Linkwhich is essentially a Shortcut in disguise because when you open aSymLinkthe system actually opens whatever is at the location that was created. so if you rename a different file to the name that wasSymLinked it will open that file, just like how a shortcut does.Symbolic Linksare a bit different from Shortcuts & act more likeAliasesdo on a Mac, but that’s a different topic.
Now, you know how when you delete a file it can be recovered because the data is still there? What happens is that when you delete a file it removes thatInodereference from the File Table. But the data still exists in those blocks & theInodestill exists in the table. If you’ve ever done file recovery where you can recover a file but not it’s name that means that the Inode was lost but the data blocks weren’t overwritten yet. It rarely happens, but it is possible. With aHard Linkwhen you delete 1 file it removes that entry from theInodebut leaves the other until all versions of that file have been removed.
Now Hard Links are created in the command prompt, with a very simple single line of code, but if you are uncomfortable in the command prompt or, as I discovered, if you are doing a lot of them, there is a shell extension called Link Shell Extension that makes it super easy. Before Quarantine I didn’t create them enough to try it, but since I have I love the extension. I’ll include a link in the 1st comment just in case there’s an issue with it being included.
So to create a Hard Link
mklink /h "Path of NEW file being created" "Path of ORIGINAL file"
So if I was taking a file I already had in P:\Files\MyMovie.mkv & making a Hard Link in P:\Archive\When I Was Young\EmbarassingMovie.mkv I would use the following command
mklink /h "P:\Archive\When I Was Young\EmbarassingMovie.mkv" "P:\Files\MyMovie.mkv"
Note that the file names do NOT have to be the same. Also note that you can edit the names in the future & it won’t affect the other or break the link.
Now with the Link Shell Extension you can Right click & select Pick Link Source & then Right click where you want it & select Drop As... > Hardlink or Right Drag & choose Drop Here... > Hardlink the same as you would a copy function.
Now to do this with Plex a few criteria are required
- You CANNOT create hard links within the same library. I guess Plex must use the
Inodefor the file because if you try to, say, make a special show up at the end of the season AND in theSpecialsseason Every time Plex refreshes the Metadata it will move it to the other one. You also cannot have a Special crossover of 2 shows show up in both shows in the same library. I tried many different ways, & was unable to find one that worked. - Library folders MUST exist on the same drive
- Watch status from both files will be the same. If you are watching 1 file & stop halfway through the other will show as half watched. If you mark one as
Unplayedthe other will be marked asUnplayedas well. This doesn’t apply if you have the other entry in aMovielibrary. I’m not sure exactly why, but even if the other library is using a different scanner & different Metadata Agent or is matched to a different show it carries over. But it doesn’t from aShowto aMovie
So for my 1ˢᵗ example I’m going to use a Holiday Movie Library to add Christmas Specials of Doctor Who as Movies
- My Doctor Who Episodes exist in
P:\TV\Doctor Who (2005)\ - My TV Library Points to
P:\TV\ - My
HolidayLibrary points toP:\Holiday& I have all Christmas movies in theP:\Holiday\Christmassubfolder (I have not had issues but I know some people may have issues with Special Features when in a nested folder)
I’ll use one of my newest additions for this example
1ˢᵗ I create the folder for the Hard Linked movie at P:\Holiday\Christmas\Doctor Who A Christmas Carol (2010)
Then I create the Hard Link with the following command
mklink /h "P:\Holiday\Christmas\Doctor Who A Christmas Carol (2010)\Doctor Who A Christmas Carol (2010).mp4" "P:\TV\Doctor Who (2005)\Season 5 - Smith\Matt Smith S05E14 - A Christmas Carol.mp4"
That’s it. Done. Easy
You’ll note that I used a different name for the 2nd file. I could also have used the same name & then renamed it.
For the 2ⁿᵈ example I’ll use the Link Shell Extension
Same base starting points
- My Doctor Who Episodes exist in
P:\TV\Doctor Who (2005)\ - My TV Library Points to
P:\TV\ - My
HolidayLibrary points toP:\Holiday& I have all Christmas movies in theP:\Holiday\Christmassubfolder
1ˢᵗ I create the folder for the Hard Linked movie at P:\Holiday\Christmas\Doctor Who The Runaway Bride (2006)
Then I create the Hard Link by right-dragging from P:\TV\Doctor Who (2005)\Season 2 - Tennant\ the file Tennant S02E14 - The Runaway Bride.mp4 to P:\Holiday\Christmas\Doctor Who The Runaway Bride (2006)
one the Pop-Up Menu I select Drop Here... > Hardlink
I now rename P:\Holiday\Christmas\Doctor Who The Runaway Bride (2006)\Tennant S02E14 - The Runaway Bride.mp4 to P:\Holiday\Christmas\Doctor Who The Runaway Bride (2006)\Doctor Who The Runaway Bride (2006).mp4
It sounds more complicated, but it’s actually easier.
For the 3ʳᵈ example I’ll use Link Shell Extension but I’ll create the original file in the same directory & then move it.
Same base starting points
- My Doctor Who Episodes exist in
P:\TV\Doctor Who (2005)\ - My TV Library Points to
P:\TV\ - My
HolidayLibrary points toP:\Holiday& I have all Christmas movies in theP:\Holiday\Christmassubfolder
In the folder P:\TV\Doctor Who (2005)\Season 1 - Eccleston\ I right-drag the file Eccleston S01E14 - The Christmas Invasion.mp4 & release on another part of the same folder
On the PopUp I select Drop Here... > Hardlink
I rename Eccleston S01E14 - The Christmas Invasion - Hardlink.mp4 to Doctor Who The Christmas Invasion (2005).mp4
I then create the folder P:\Holiday\Christmas\Doctor Who The Christmas Invasion (2005)\
I drag Doctor Who The Christmas Invasion (2005).mp4 from P:\TV\Doctor Who (2005)\Season 1 - Eccleston\ to P:\Holiday\Christmas\Doctor Who The Christmas Invasion (2005)\
Every file plays without issue.
It’s a very simple process, practically foolproof, but I know a lot of people are afraid to mess with things they don’t understand like Hard Links So I hope this helps make that easier