Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 檔案與目錄的「x」執行權限深度解析

編輯:Linux 教學

權限字元「x」的雙重含義

在 Linux 權限模型中,x(執行位元)對「檔案」與「目錄」具有截然不同的語義:

對象類型x 權限代表意義
一般檔案允許將該檔案作為程式/腳本直接執行(需同時具備讀取權限)
目錄允許 進入(cd) 該目錄,並存取其中的檔案清單(需搭配 r 權限才能列出內容)

實戰範例:Shell 腳本執行權限

假設有一支腳本 a.sh,權限為 rw-(缺少 x):

$ ./a.sh
bash: ./a.sh: Permission denied

此時僅能透過解譯器間接執行:

$ sh a.sh    # 或 bash a.sh

加上執行權限後,即可直接呼叫:

$ chmod u+x a.sh
$ ./a.sh     # 成功執行

補充說明

  • 目錄若只有 x 無 r,可 cd 進入且若知檔名可讀取檔案,但無法用 ls 列出清單。
  • 二進位執行檔(ELF)與腳本檔皆需 x 位元;腳本額外需 r 以便解譯器讀取原始碼。
  • 權限數值對應:r=4, w=2, x=1,故 7 代表 rwx。
Copyright © Windows教程網 All Rights Reserved