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 修改檔案/裝置擁有者:chown -R 遞歸變更實例

編輯:Linux 教學

Linux 下變更檔案或裝置的擁有者 (User) 與群組 (Group) 使用 chown 指令。需遞歸處理目錄樹時加 -R 參數。

語法


chown [-R] [USER][:GROUP] FILE...

實例:將目錄 title 及其所有子項擁有者改為 guest 群組的 su 使用者


chown -R su:guest title
  • -R:遞歸處理指定目錄及所有子目錄/檔案
  • su:guest:使用者 su,群組 guest (冒號分隔)
  • title:目標目錄/檔案路徑

常見變體

chown user filechown :group filechown user: filechown -R root:root /opt/app
指令效果
僅變更使用者,群組不變
僅變更群組 (冒號前空白)
變更使用者,群組設為該使用者登入群組
遞歸設為 root 擁有

權限需求

  • 一般使用者僅能變更自己擁有的檔案群組 (需屬於目標群組)
  • 變更使用者擁有者需 root 權限 (sudo)

查看當前擁有者


ls -l title
# 輸出範例: -rw-r--r-- 1 su guest 1024 May 20 10:00 title

掌握 chown -R,批量權限管理不再手動逐個修改。

Copyright © Windows教程網 All Rights Reserved