Skip to content

Instantly share code, notes, and snippets.

@jflyoo
Created December 30, 2022 18:38
Show Gist options
  • Save jflyoo/602d6926f123b02566b140dcd31f4c37 to your computer and use it in GitHub Desktop.
Save jflyoo/602d6926f123b02566b140dcd31f4c37 to your computer and use it in GitHub Desktop.
NTFS Linking Experiments
Create one directory "dir1" in Lab\dirA
Create junction "junctionA1" in Lab pointing to Lab\dirA\dir1
Create symlinkd "symlinkdA1" in Lab pointing to Lab\dirA\dir1
Create file "test.txt" in Lab with contents "lab test"
Create symlink "test.txt.lnk" in Lab pointing to Lab\test.txt
Create hard link "test_hard.txt in Lab pointing to Lab\test.txt
Create shortcut "test_shortcut.lnk" in Lab pointing to Lab\test.txt

NTFS Linking Experiment Results

Support UNC relative paths Can move target Can move link Can remove target
Symlink X O X
Hard link O O O
Junction X X X
Shortcut O O O

Key

  • An empty space indicates that research was not conducted
  • X indicates a negative result
  • O indicates a positive result

Experiment definitions

  • target real and original are all descriptions of the target file. In mklink terms, this is called the Target
  • symbolic link and soft link are synonymous
echo off
echo Please make sure base_loc variable is set to the desired drive (e.g. C:, D:, E:)
set base_loc=C:
set proj_dir=%base_loc%\Projects\LinkProject
set lab_dir=%proj_dir%\Lab
set target_dir=%lab_dir%\dirA\dir1
REM These are the cleanup lines . . .
REM echo Cleaning up directories
REM del %lab_dir%\test.txt
REM rmdir %target_dir%
REM rmdir %lab_dir%\JunctionA1
REM del %lab_dir%\SymlinkdA1
REM del %lab_dir%\test.txt.lnk
REM del %lab_dir%\test_hard.txt
REM Making a target directory
REM We will be moving this to do target moving testing
echo Creating target directory %target_dir% . . .
md %target_dir%
REM Create a junction
echo Creating junction . . .
mklink /J %lab_dir%\JunctionA1 %target_dir%
REM Create a symlinkd
echo Creating symlinkd . . .
mklink /d %lab_dir%\SymlinkdA1 %target_dir%
REM Create file
echo Creating target file . . .
echo lab test > %lab_dir%\test.txt
REM Create soft link / symlink to the file
echo Creating a symlink/"soft link" to the file . . .
mklink %lab_dir%\test.txt.lnk %lab_dir%\test.txt
REM Create hard link to the file
echo Creating a hard link to the file . . .
mklink /h %lab_dir%\test_hard.txt %lab_dir%\test.txt
REM Create shortcut to the file
echo Create a shortcut to the file (manually, please) . . .
pause
REM Now display the results of dir /a:l
echo Running DIR /A:L
dir /a:L /s %lab_dir%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment