2016-11-25 149 views
-2
ln -sf 

不會覆蓋給定的符號鏈接。如何使用'ln'替換符號鏈接

+2:34% ls -ld ema*   
drwxr-xr-x 22 b users 4096 Nov 25 14:33 emacs 
drwxr-xr-x 22 b users 4096 Nov 25 14:29 emacs-201611181546 
-rw-r--r-- 1 b users 0 Nov 25 14:34 emacs-current 
+2:34% ln -fs emacs-201611181546 emacs-current 
+2:34% ls -ld ema*        
drwxr-xr-x 22 b users 4096 Nov 25 14:33 emacs 
drwxr-xr-x 22 b users 4096 Nov 25 14:29 emacs-201611181546 
lrwxrwxrwx 1 b users 18 Nov 25 14:34 emacs-current -> emacs-201611181546 
+2:34% ln -fs emacs emacs-current 
+2:34% ls -ld ema*    
drwxr-xr-x 22 b users 4096 Nov 25 14:33 emacs 
drwxr-xr-x 22 b users 4096 Nov 25 14:34 emacs-201611181546 
lrwxrwxrwx 1 b users 18 Nov 25 14:34 emacs-current -> emacs-201611181546 

我本來期望

lrwxrwxrwx 1 b users 18 Nov 25 14:34 emacs-current -> emacs 

至於解決方法,我可以明確地斷開鏈接。

+2:34% unlink emacs-current 
+2:35% ls -ld ema*   
drwxr-xr-x 22 b users 4096 Nov 25 14:33 emacs 
drwxr-xr-x 22 b users 4096 Nov 25 14:34 emacs-201611181546 
+2:35% ln -fs emacs emacs-current 
+2:35% ls -ld ema*    
drwxr-xr-x 22 b users 4096 Nov 25 14:33 emacs 
drwxr-xr-x 22 b users 4096 Nov 25 14:34 emacs-201611181546 
lrwxrwxrwx 1 b users 5 Nov 25 14:35 emacs-current -> emacs 

但我寧願

ln 

做的工作。

這可能嗎?怎麼樣?

+1

爲什麼downvote?跟隨或不跟隨可能會引起混淆。 – ceving

回答

1

man ln

SYNOPSIS 
    ln [OPTION]... [-T] TARGET LINK_NAME (1st form) 
    ln [OPTION]... TARGET     (2nd form) 
    ln [OPTION]... TARGET... DIRECTORY  (3rd form) 
    ln [OPTION]... -t DIRECTORY TARGET... (4th form) 

DESCRIPTION 
    In the 1st form, create a link to TARGET with the name LINK_NAME. 
    In the 2nd form, create a link to TARGET in the current directory. 
    In the 3rd and 4th forms, create links to each TARGET in DIRECTORY. 

你有第三形式,因爲你的鏈接是一個目錄的鏈接。

+2

。 。 。你可以通過使用'-T'標誌強制第一種形式來達到預期效果:'ln -Tfs emacs emacs-current'。 – ruakh