Windows·29 questions

How to create symbolic and hard links in the NTFS file system using mklink?

Answer

Symbolic and hard links in Windows allow you to efficiently manage the file structure, save disk space, and provide access to data from different folders without duplicating them. This mechanism is supported by the NTFS file system and is actively used by developers to organize dependencies and projects.

To create links in the command line, the built-in `mklink` utility is used. It is important to note that creating most types of links requires running the command prompt with administrator privileges.

To create a hard link to a file, use the command `mklink /H link target`. A hard link points to the same disk sectors as the original, so modifying the file in one place changes the data everywhere. Deleting the original does not remove the contents as long as at least one hard link exists.
To create a symbolic link to a file, use the command `mklink link target`. Such a link is similar to an advanced shortcut at the file system level, which is supported by any programs.
To create a symbolic link to an entire folder, use the command `mklink /D link target`. This allows you to transparently redirect requests for one directory to a completely different drive.

The main difference between link types lies in their behavior when data is moved. Hard links only work within a single logical drive and point to physical data, whereas symbolic links can point to paths on other drives and even network resources.

Using links helps solve many practical tasks, such as moving heavy compiler cache directories to a fast SSD while preserving the project structure on another drive, or organizing convenient access to shared configuration files from various working environments.

Was this answer helpful?

More questions in this topic

Related questions from other topics