一、chmod命令及其使用
chmod命令用於修改文件或目錄的許可權,可以控制文件或目錄的讀、寫、執行許可權。使用方法:chmod [who] [+ | - | =] [permission] filename/directory
其中,who代表許可權被賦予給誰,+、-、=分別表示添加許可權、取消許可權和直接設置許可權,permission表示許可權設置值,filename/directory表示需要修改許可權的文件或目錄名稱。
二、chmod -x命令的作用
chmod -x命令用於移除文件或目錄執行許可權。在Linux系統中,目錄的執行許可權表示是否擁有進入該目錄的許可權,文件的執行許可權表示是否能夠執行該文件。使用chmod -x命令可以禁止文件的執行和目錄的進入,提高系統的安全性。
使用方法:chmod -x filename/directory
三、實例演示
假設現在有一個名為test.sh的文件(文件內容為echo “hello world!”),我們需要將該文件的執行許可權去除。
$ ls -l -rw-r--r-- 1 root root 19 Jan 1 00:00 test.sh # 查看文件許可權 $ chmod -x test.sh # 移除執行許可權 $ ls -l -rw-r--r-- 1 root root 19 Jan 1 00:00 test.sh # 許可權已經修改
接下來我們還需要將一個名為testdir的目錄的執行許可權去除。
$ ls -ld testdir drwxr-xr-x 2 root root 4096 Jan 1 00:00 testdir # 查看目錄許可權 $ chmod -x testdir # 移除目錄執行許可權 $ ls -ld testdir drw-r--r-- 2 root root 4096 Jan 1 00:00 testdir # 許可權已經修改
四、小結
通過本文,我們了解了chmod命令的用法,並重點介紹了chmod -x命令的作用與使用方法,可以掌握在Linux系統中移除文件或目錄執行許可權的方法。
原創文章,作者:MNEW,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/143157.html