Vincec's Dimension

Symbolic Links

Word count: 627 / Reading time: 3 min
2018/06/28 Share

因为 hexo 的目录结构, 我想要分别 git 备份我的 source/ 等博客本地的资源和 public/ 公共 host 文件夹。push public/ to vcec.gitlab.io, 而备份 source/themes/ 等在一个 private 的 blog-source 下, 于是使用一个链接的文件夹便是极好的了,每次在一个新电脑上建一个 blog/ 文件夹, 然后从两个 git 文件夹下分别链接到 blog/ 内, hexo newhexo g 后的变化就会自己生成到外部的 vcec.gitlab.ioblog-source 文件包内了

Because of the folder structure of hexo, it becomes difficult when I want to backup my local source/ resource and public hosted public/ resource.

I plan to keep all files in vcec.gitlab.io in my gitlab page always be same as public/, while backup all other including source/ and themes/ files and folders into a private blog-source in my gitlab page. Thus if there is a linked way of operating those source folder and target folder, that will is the best.

Windows

Check my small mklink GUI version tools for Windows - vSymlinks

English badge

Windows 本身有个 shortcut 的 link,但是那不是我们想要的,那只会生成一个.lnk文件而不是完整的文件或文件夹目录;我们需要的是 Symbolic Links。

Windows has a link approach named shortcut, but that can only generate a .lnk file but not a link path of certain files or folders. We need Symbolic Links.

“Symbolic Links differ from Shortcuts in that they offer a transparent* pathway to the desired data object, with a shortcut (.lnk), something has to read and interpret the content of the shortcut file and then open the file that it references (i.e. it is a two-step process). When an application uses a symlink it gains immediate access to the data object referenced by the symlink (i.e. it is a one-step process).” 1

在CMD的管理员下运行

Run the code under the CMD Admin.

1
2
3
4
5
# create a file symbolic link so that typing pad.exe will allow you to launch notepad.exe.
mklink pad.exe notepad.exe

# create a symbolic link called a fruit that points directly to the folder oranges.
mklink /D c:\fruit c:\apples\bananas\oranges


使用lnk


使用mklink

Linux

Terminal Way

1
ln -s /folderorfile/link/will/point/to /name/of/the/link

Desktop Way

hold Shift + Ctrl and drag the file or folder you want to link to to the location where you want the shortcut.

KDE dolphins 中拖动可以直接选择 move, copy 或者 link

Under KDE Dolphins, we can directly choose move, copy or link when we drag files.

macOS

Terminal Way

Same as Linux

1
2
3
4
5
6
7
ln -s /path/to/original /path/to/link
ln -s /Users/name/Downloads /Users/name/Desktop
ln -s "/Users/name/My Files" "/Users/name/Desktop/My Link"
sudo ln -s /path/to/original /path/to/link

#remove
rm /path/to/link

Desktop Way

SymbolicLinker


SymbolicLinker.app


Select Services


Select Make Symbolic Link

Reference

Author: VINCEC

Permalink: https://vince-amazing/blog/2018/06/28/symbolic-link/

Date: June 28th 2018, 12:29:12

Copyright license: The article usingCC licensing 4.0

CATALOG
  1. 1. Windows
  2. 2. Linux
    1. 2.1. Terminal Way
    2. 2.2. Desktop Way
  3. 3. macOS
    1. 3.1. Terminal Way
    2. 3.2. Desktop Way
  4. 4. Reference