是否可以使用命令行通过文件夹 cd 到快捷方式

Tah*_*aus 4 windows unix command-line

我的桌面上有一个文件夹的快捷方式(因为我不直接在上面存储文件)。当我在命令行中的桌面上时,是否可以进入快捷方式指向的目录?

我想知道在 Windows 和基于 Unix 的操作系统中是否可行。

小智 5

是的,这在 Windows 上是可能的。您需要制作目录符号链接。以以下命令为例:

> cd %userprofile%
> mklink /D OMGDOCUMENTS Documents
> cd OMGDOCUMENTS
> dir
Run Code Online (Sandbox Code Playgroud)

您会注意到 的内容\OMGDOCUMENTS\Documents. 如果然后返回父文件夹%userprofile%并运行dir命令,您将看到您的\OMGDOCUMENTS文件夹将显示为符号链接。


kaz*_*oni 2

请参阅Windows 7 和 cd 到符号链接- 长短,如果您有实际的符号链接,它应该按您的预期工作。如果您只有快捷方式(*.lnk 文件),那么这些不是链接,也不会执行您想要的操作。

就 Linux 而言:

username@hostname ~ $ mkdir /home/username/test     # make new directory
username@hostname ~ $ touch /home/username/test/somefile    # make a file in directory
username@hostname ~ $ cd /tmp   # changing to temp folder
username@hostname /tmp $ ln -s /home/username/test testlink # make a link to the folder made previously
username@hostname /tmp $ ls -la test*   # test to show the link connects to the folder I made
lrwxrwxrwx 1 username username 18 Jun 23 11:49 testlink -> /home/username/test
username@hostname /tmp $ cd testlink    # can we traverse into the link?
username@hostname /tmp/testlink $ ls -la    # testing...
-rw-r--r--  1 username username    0 Jun 23 11:49 somefile  # We can!
Run Code Online (Sandbox Code Playgroud)