week3 Linux 目錄結構
1.Linux 目錄結構
Windows: 以多根的方式組織檔案 C:\ D:\ E:\
Linux: 以單根的方式組織檔案 /
/bin 存放二進位制可執行檔案和常用命令。
/dev 存放裝置檔案
/boot 存放的系統啟動相關的檔案例如 kernel,grub(載入程式)
/etc 存放系統管理和配置檔案
/home 存放所有使用者檔案的根目錄
/usr 用於存放系統應用程式
/tmp 存放臨時檔案 (/var/tmp程序產生的臨時檔案)
絕對路徑: 從/開始的路徑(檔案從根目錄開始所在的位置)
相對路徑: 相對於當前目錄開始(相當於windows下的快捷方式所在位置)
2. 檔案管理:建立/複製/移動/刪除
2.1 建立檔案 touch (建立空檔案)
touch file
建立一個file0檔案:
此檔案建立在/(根目錄下)如想指定所在目錄 touch 目錄 檔案
這裡舉例在/etc下建立一個a0檔案:
touch /etc/a0
2.2 建立目錄 mkdir
mkdir 目錄
在根目錄下建立一個A1目錄
mkdir A1
mkdir 的一些差數引用:
2.3 複製 cp
cp file /(指定目錄)
這裡舉例建立在a0檔案裡寫上內容複製到剛建立的A1目錄下:
[[email protected] ~]# vi a0
[[email protected] ~]# cp a0 A1
[[email protected] ~]# cd A1
[[email protected] A1]# ll
total 4
-rw-r–r--. 1 root root 8 Sep 27 20:02 a0
[[email protected] A1]# ls
a0
[[email protected] A1]# cat a0
nihaoa
2.4 移動 mv
Usage: mv [OPTION]... [-T] SOURCE DEST
[[email protected] ~]# cat f2
[[email protected] ~]# echo 'aaa' >> f2
[[email protected] ~]# cat f2
aaa
[[email protected] ~]# mv f2 /home/dir1 (將f2移到/home/dir1)
[[email protected] ~]# more /home/dir1
aaa
2.5 刪除 rm
-r 遞迴
-f force 強制
-v 詳細過程
[[email protected] ~]# ls
a AAA anaconda-ks.cfg etc findresults www.linuxprobe.com
a1 aa.tar.gz a.tar.gz fild history
A1 a.log b file0 localhost}
[[email protected] ~]# rm -rf a1
[[email protected] ~]# ls
a aa.tar.gz a.tar.gz fild history
A1 a.log b file0 localhost}
AAA anaconda-ks.cfg etc findresults www.linuxprobe.com
3. 檔案型別的看法
通過顏色判斷檔案的型別是不一定正確的!!!
Linux 系統中檔案是沒有副檔名!!!
方法一:
ls -l 檔名 //看第一個字元
- 普通檔案(文字檔案,二進位制檔案,壓縮檔案,電影,圖
片。。。)
d 目錄檔案(藍色)
b 裝置檔案(塊裝置)儲存裝置硬碟,U 盤 /dev/sda, /dev/sda1
c 裝置檔案(字元裝置)印表機,終端 /dev/tty1
s 套接字檔案
p 管道檔案
l 連結檔案(淡藍色)
方法二: file
[[email protected] ~]# file a1
a1: ASCII text
[[email protected] ~]# file aa.tar.gz
aa.tar.gz: gzip compressed data, from Unix, last modified: Sat Sep 22 14:32:02 2018
[[email protected] ~]# file /home/
/home/: directory
4.檢視檔案所在位置
whereis [options] file
也可以檢視命令所在位置:如查詢touch 所在位置
whereis touch
5. 基本許可權 UGO
5.1檔案許可權管理: UGO 設定基本許可權(r、w、x)
許可權物件 | 許可權型別 |
---|---|
屬主: u | 讀:r 4 |
屬組 :g | 寫: w 2 |
其他人 :o | 執行: x 1 |
5.2 chmod 更改許可權
Usage: chmod [OPTION]... MODE[,MODE]... FILE...
對許可權物件ugo增加去除許可權型別rwx:
chmod (ugo) (+/—) (rwx) 使用符號
[[email protected] ~]# ll file0
-rw-r–r--. 1 root root 0 Sep 27 19:37 file0
[[email protected] ~]# chmod u+x file0
[[email protected] ~]# chmod g+w file0
[[email protected] ~]# chmod g+x file0
[[email protected] ~]# chmod o+w file0
[[email protected] ~]# chmod o+x file0
[[email protected] ~]# ll file0
-rwxrwxrwx. 1 root root 0 Sep 27 19:37 file0
還原file0許可權
[[email protected] ~]# chmod u-x file0
[[email protected] ~]# chmod g-w file0
[[email protected] ~]# chmod g-x file0
[[email protected] ~]# chmod o-w file0
[[email protected] ~]# chmod o-x file0
還可以使用數字更改許可權
[[email protected] ~]# ll file0 (檢視file0檔案原先許可權)
-rw-r–r--. 1 root root 0 Sep 27 19:37 file0 (原許可權為644)
[[email protected] ~]# ll file0
-rw-r–r--. 1 root root 0 Sep 27 19:37 file0
[[email protected] ~]# chmod 763 file0 (更改file0許可權為763)
[[email protected] ~]# ll file0
-rwxrw–wx. 1 root root 0 Sep 27 19:37 file0
5.3 許可權對檔案的影響
[[email protected] ~]# mkdir /dir10
[[email protected] ~]# touch /dir10/file1
[[email protected] ~]# chmod 777 /dir10/file1
[[email protected] ~]# ll -d /dir10/
drwxr-xr-x. 2 root root 4096 3 月 11 18:37 /dir10/
[[email protected] ~]# ll /dir10/file1
-rwxrwxrwx. 1 root root 0 3 月 11 18:37 /dir10/file1
[[email protected] ~]$ cat /dir10/file1
[[email protected] ~]$ rm -rf /dir10/file1
rm: 無法刪除"/dir10/file1": 許可權不夠
為什麼普通使用者對檔案file1沒有許可權刪除呢?首先管理員下給/dir10/file1賦予了最高許可權應該是可以刪除的,那為什麼出現這種情況,因為組和其他使用者對目錄/dir10沒有可寫許可權這就是為什麼其他使用者不能刪除/dir/file1;這裡就像你回家取東西一樣首先你得有進房子的許可權(鑰匙)你才能進入目錄下(進入房子)修改檔案(取出你的東西);