溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

OS X中快捷方式(Aliases-替身, Symbolic Links-符號鏈接, and Hard Links-硬鏈接)的區(qū)別

發(fā)布時(shí)間:2020-06-15 06:53:26 來源:網(wǎng)絡(luò) 閱讀:6123 作者:h2appy 欄目:系統(tǒng)運(yùn)維

OS X文件系統(tǒng)支持3種類型的快捷鏈接:
1. 替身(alias)
2. 符號鏈接(symbolic link)
3. 硬鏈接(hard link)

快捷鏈接,就是一個(gè)小文件,它的內(nèi)容包含了一些“指向文件、文件夾、驅(qū)動(dòng)器或者網(wǎng)絡(luò)設(shè)備等文件系統(tǒng)對象”的信息。

快捷鏈接能讓用戶更方便的訪問到文件、文件夾、驅(qū)動(dòng)器或者網(wǎng)絡(luò)設(shè)備等文件系統(tǒng)對象。

當(dāng)用戶對快捷鏈接進(jìn)行某種操作時(shí),系統(tǒng)首先讀取快捷鏈接文件(其中包含了原始對象的位置信息),找到原始文件位置,然后系統(tǒng)打開原始對象進(jìn)行相應(yīng)操作。多數(shù)情況下,通過快捷鏈接找原始對象的過程對用戶和應(yīng)用程序是透明的,不可見的。


使用快捷鏈接的一個(gè)好處是,當(dāng)用戶訪問一個(gè)具有很深目錄結(jié)構(gòu)的文件時(shí),不用再一級一級的打開文件夾,而是直接雙擊快捷鏈接,就打開了相應(yīng)的文件。

1. 替身是OS X自己的概念,并且是Finder層級的感念,一些終端下的Unix程序(比如vim)不能正確理解替身文件。但是,替身卻是OS X下的最多才多藝的快捷鏈接。比如,創(chuàng)建了替身之后,替身文件和原始文件可以任意移動(dòng)位置,這不會影響替身文件指向原始文件,因?yàn)樘嫔砦募邪嗽嘉募膇node信息,而inode信息是唯一的,即使文件被移動(dòng)來移動(dòng)去。處理過程大概是這個(gè)樣子,當(dāng)用戶訪問替身文件時(shí),系統(tǒng)分析替身文件,找到原始文件的路徑信息,然后判斷原始文件是否存在,如果存在就訪問它,如果不存在,就找具有相同inode的文件,然后訪問該文件。

2. 符號鏈接(Symbolic Links)是Unix的概念,所以Linux、OS X都會繼承這個(gè)概念。
符號鏈接對比替身的優(yōu)勢是,不管是Finder層面還是Terminal層面,都是有效的。
符號連但是,因?yàn)榉栨溄又淮鎯α嗽嘉募穆窂叫畔?,所以?dāng)原始文件被移走了,符號鏈接文件就找不到原始文件了。另一種情況是符號鏈接文件中存儲的是相對路徑,如果相對路徑關(guān)系改變了,也就找不到原始文件了。


替身(alias)符號鏈接(Symbolic Link)硬鏈接(Hard Link)
鏈接文件存儲的信息文件路徑和inode文件路徑(相對路徑或絕對路徑)inode
鏈接依據(jù)以inode的相同為鏈接依據(jù)以路徑相同為鏈接依據(jù)以路inode相同為鏈接依據(jù)
優(yōu)點(diǎn)鏈接文件和原始文件可以隨意移動(dòng),都不會改變鏈接關(guān)系
如果是絕對路徑,原始文件移動(dòng)到別處了,鏈接關(guān)系將失效。如果是相對路徑,原始文件和符號鏈接文件的相對路徑關(guān)系改變了,鏈接關(guān)系將失效。只要是鏈接文件中存儲的路徑和原始文件的路徑一致,鏈接關(guān)系就是有效的。所以,即使原始文件被替換成另外一個(gè)文件了,只要路徑能對應(yīng)的上,鏈接關(guān)系就是有效的。

缺點(diǎn)OS X自己的概念,F(xiàn)inder層面的概念,Terminal下的一些Unix程序(如vim)不能理解替身文件內(nèi)容,也就不能理解鏈接關(guān)系,這時(shí)鏈接關(guān)系將失效。
是Unix的概念,所以Linux和OS X完全繼承了下來,無論是Finder下,還是Terminal下的Unix程序,都能正確理解符號鏈接文件,也就能理解鏈接關(guān)系
創(chuàng)建方法
Finder中右鍵點(diǎn)擊文件,彈出的快捷菜單中有創(chuàng)建替身功能
ln -s 原始文件 符號鏈接文件


參考:


http://macs.about.com/od/faq1/f/What-Are-Aliases-Symbolic-Links-And-Hard-Links-In-Mac-Os-X.htm


Question: What Are Aliases, Symbolic Links, and Hard Links in Mac OS X?

What are shortcut links? How do I determine which type of shortcut link I should use to find my files more easily?

Answer:

The OS X file system supports several types of shortcut links to files and folders. Shortcut links can make it easy to navigate to objects that are buried deep within the OS X file system. OS X supports three types of links: aliases, symbolic links, and hard links.

All three types of links are shortcuts to the original file system object. A file system object is usually a file on your Mac, but it can also be a folder, a drive, even a networked device.

Overview of Aliases, Symbolic Links, and Hard Links

Shortcut links are small files that reference another file object. When the system encounters a shortcut link, it reads the file, which contains information about where the original object is located, and then proceeds to open that object. For the most part, this happens without apps recognizing that they've encountered a link of some type. All three types of links try to appear transparent to the user or app that makes use of them.

This transparency allows shortcut links to be used for many different purposes; one of the most common is to conveniently access a file or folder that is buried deep in the file system. For instance, you may have created an accounting folder in your Documents folder for storing bank statements and other financial information. If you use this folder often, you can create an alias to it. The alias will appear on the desktop. Instead of using the Finder to navigate through multiple folder levels to access the accounting folder, you can simply click on its desktop alias. The alias will take you right to the folder and its files, short-circuiting a long navigation process.

Another common use for file system shortcuts is to use the same data in multiple locations, without having to either duplicate the data or keep the data synced.

Let's return to our accounting folder example. Perhaps you have an application that you use to track stock market picks, and the app needs to store its data files in some predefined folder. Instead of copying the accounting folder to a second location, and then having to worry about keeping the two folders in sync, you can create an alias or a symbolic link, so that the stock trading app sees the data in its dedicated folder but actually accesses the data that's stored in your accounting folder.

To sum things up: all three types of shortcuts are simply methods of accessing an object in your Mac's file system from other than its original location. Each type of shortcut has unique features that are better suited for some uses than others. Let's take a closer look.

Link Types

Aliases: This type of shortcut is the oldest for the Mac; its roots go all the way back to System 7. Aliases are created and managed at the Finder level, which means that if you're using Terminal or a non-Mac application, such as many UNIX apps and utilities, an alias won't work. OS X seems to see aliases as small data files, which they are, but it doesn't know how to interpret the information they contain.

This may seem to be a drawback, but aliases are actually the most powerful of the three types of shortcuts. For Mac users and apps, aliases are also the most versatile of the shortcuts.

When you create an alias for an object, the system creates a small data file that includes the current path to the object, as well as the object's inode name. Each object's inode name is a long string of numbers, independent of the name you give the object, and guaranteed to be unique to any volume or drive your Mac uses.

Once you create an alias file, you can move it to any location in your Mac's file system, and it will still point back to the original object. You can move the alias about as many times as you like, and it will still connect to the original object. That's pretty clever, but aliases take the concept a step further.

In addition to the moving the alias, you can also move the original item anywhere in your Mac's file system; the alias will still be able to find the file. Aliases can perform this seemingly magic trick because they contain the inode name of the original item. Because each item's inode name is unique, the system can always find the original file, no matter where you relocate it.

The process works like this: When you access an alias, the system checks to see if the original item is at the pathname stored in the alias file. If it is, then the system accesses it, and that's that. If the object has been moved, the system searches for a file that has the same inode name as the one stored in the alias file. Once it finds a matching inode name, the system then connects to the object.

Symbolic Links: This type of shortcut is part of UNIX and Linux file systems. Because OS X is built on top of UNIX, it fully supports symbolic links. Symbolic links are similar to aliases in that they are small files that contain the pathname to the original object. But unlike aliases, symbolic links don't contain the inode name of the object. If you move the object to a different location, the symbolic link will be broken, and the system won't be able to find the object.

That may seem like a weakness, but it's also a strength. Since symbolic links find an object by its pathname, if you replace an object with another object that bears the same name and is in the same location, the symbolic link will continue to work. This makes symbolic links a natural for version control. For example, you could create a simple version control system for a text file called MyTextFile. You could save older versions of the file with a number or date appended, such as MyTextFile2, and save the current version of the file as MyTextFile.

Hard Links: Like symbolic links, hard links are part of the underlying UNIX file system. Hard links are small files that, like aliases, contain the original item's inode name. But unlike aliases and symbolic links, hard links don't contain the pathname to the original object. You would typically use a hard link when you want a single file object to appear in multiple places. Unlike with aliases and symbolic links, you can't delete the original hard-linked object from the file system without first removing all hard links to it.

Related Articles
  • Macintosh File Types: Alias

  • praliases - Linux Command - Unix Command

  • aliases.sendmail - Linux Command - Unix Command

  • aliases - Linux Command - Unix Command

  • sane-dll - Linux Command - Unix Command


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI