一、linux檔案和目錄許可權操作
每乙個檔案和目錄的訪問許可權都有三組,每組用三位表示:
(1)檔案所屬的使用者具有讀、寫和可執行許可權;(2)和檔案、目錄所屬的使用者的同組使用者只有讀和寫的許可權;(3)其他使用者具備讀的許可權;
-rwxrw-r-- 1 xiaoru xiaoru 444 jun 25 07:42 variableshell.sh
修改檔案許可權的方法:
其中+/-/=分別代表:增加某個許可權;取消某個許可權;賦值某個許可權其他許可權清除;
修改增加某個許可權:
(1)的許可權:chmod u+r/w/x 檔名;修改(2)的許可權 chmod g+r/w/x 檔名;修改(3)的許可權 chmod o+r/w/x 檔名;
減掉某個許可權:
(1)的許可權:chmod u-r/w/x 檔名;修改(2)的許可權 chmod g-r/w/x 檔名;修改(3)的許可權 chmod o-r/w/x 檔名;
賦值成某個許可權:
(1)的許可權:chmod u=r/w/x 檔名;修改(2)的許可權 chmod g=r/w/x 檔名;修改(3)的許可權 chmod o=r/w/x 檔名;
修改全部的許可權chmod a+r/w/x 檔名;當然也可以直接chmod 666(許可權值) 檔名。
二、linux檔案和資料夾改變所屬使用者的操作
chown -h 使用者組 檔案/目錄;將該檔案/目錄所屬使用者組由當前使用者組修改為新的使用者組;
-rw-rw-r-- 1 xiaoru xiaoru 120 jun 25 03:07 file.txt
執行sudo chown -h renyunjun file.txt
-rw-rw-r-- 1 renyunjun xiaoru 120 jun 25 03:07 file.txt
三、liunx下特殊許可權suid與sgid
1、設定sgid
使用chmod g+s filename;只要設定sgid之後該檔案將具有所有組使用者的特權,即不論那個使用者只要能夠看到該檔案,那麼就具備和該檔案所屬組相同的許可權,可以任意操作該檔案;
例如:下xiaoru使用者下:
-rwxrwxr-x 1 xiaoru xiaoru 444 jun 25 07:42 variableshell.shchmod u+s filename
chmod g+s filename 執行之後
-rwxrwsr-x 1 xiaoru xiaoru 444 jun 25 07:42 variableshell.sh
此時切換到使用者renyunjun;
-rwxrwsr-x 1 xiaoru xiaoru 444 jun 25 07:42 variableshell.sh
便可以執行該檔案
2、設定suid
使用chmod u+s filename ,設定了suid之後執行者就擁有檔案所有者的全部許可權,但是在做實驗的過程中發現並不是這樣成子,貌似設定了當前使用者的suid特權之後只有當前使用者才有執行許可權;
還存在一定的疑問,希望各位博友高手幫忙解釋
四、檔案的查詢
find . -name 'commond*' -print 查詢當前目錄下以commond開頭的檔案並輸出到shell
find 。 -mtime -1 -print查詢更改時間距離今天1天內的檔案
find . -name 'c*' -mtime -1 -print 查詢以c開頭的檔案且更改時間距離今天1天內的檔案
sudo find /dev -type b -print查詢dev下的所有塊裝置檔案並顯示
sudo find /run -type p -print 查詢/run下的所有管道檔案
run/systemd/inhibit/9.ref
/run/systemd/inhibit/8.ref
/run/systemd/inhibit/7.ref
/run/systemd/inhibit/6.ref
/run/systemd/inhibit/1.ref
/run/systemd/sessions/c2.ref
順便諮詢一下什麼事管道檔案?在linux下的這些檔案起到什麼作用?
sudo find /run -type p -exec ls -l {} \;exec後面可以跟隨shell下執行命令,例如刪除檔案等等;
prw------- 1 root root 0 jun 26 04:44 /run/systemd/inhibit/9.ref
prw------- 1 root root 0 jun 26 04:44 /run/systemd/inhibit/8.ref
prw------- 1 root root 0 jun 26 04:44 /run/systemd/inhibit/7.ref
prw------- 1 root root 0 jun 26 04:44 /run/systemd/inhibit/6.ref
prw------- 1 root root 0 jun 26 04:34 /run/systemd/inhibit/1.ref
prw------- 1 root root 0 jun 26 04:44 /run/systemd/sessions/c2.ref
五、文字編輯器
替換檔案中的字元:
(1)/word自游標位置起向下查詢word字元
(2)?word自游標位置起向上查詢word字元
(3)n1,n2s/word1/word2/g將n1行和n2行之間的word1替換為word2;
(4)1,$s/word1/word2/g將第一行到最後一行所有的word1替換為word2;
vi有倆種模式,一種為編輯模式,另一種為命令模式;
linux檔案系統和檔案結構
普通檔案 regular file 就是一般訪問的檔案,由ls al顯示出來的屬性中,第乙個屬性為 例如 rwxrwxrwx 目錄檔案 directory 就是目錄,第乙個屬性為 d 例如 drwxrwxrwx 連線檔案 link 類似windows下面的快捷方式。第乙個屬性為 l 例如 lrwxr...
linux檔案系統和檔案操作
write和open函式的練習 open函式可以開啟已經存在的檔案,也可以建立檔案返回檔案描述符 int fd open 路徑 o rdwr o creat,許可權 0777 建立檔案的時候需要加許可權0777,開啟檔案不需要加 int bytes write fd,字串指標,寫入bytes大小 i...
Linux磁碟和檔案系統
linux一般使用fdisk來分割槽,fdisk基本支援所有的作業系統。fdisk是基於mbr的分割槽工具,如果使用gpt分割槽的話是不能使用fdisk的。fdisk l可以列出所有安裝的磁碟及其分割槽資訊 cat proc partitions可以檢視分割槽資訊,proc儲存系統的實時資訊 fdi...