1. 程式人生 > >Linux檔案管理學習

Linux檔案管理學習

業精於勤,荒於嬉,行成於思,毀於隨
Linux中 資料和程式都是以檔案形式儲存的。

-:普通檔案

----------.   1 root root   1244 99 08:07 shadow
----------.   1 root root   1215 99 07:52 shadow-
-rw-r--r--.   1 root root     51 815 19:58 shells

d :目錄檔案

drwxr-xr-x.   3 root root   4096 815 19:56 sound
drwxr-xr-x.   2
root root 4096 815 20:00 ssh drwxr-xr-x. 2 root root 4096 815 19:54 ssl drwx------. 2 root root 4096 622 2012 sssd

l :連結檔案

lrwxrwxrwx. 1 root root           3 1027 01:00 dvd -> sr0
lrwxrwxrwx. 1 root root           3 1027 01:00 dvd1 -> sr1
lrwxrwxrwx. 1 root root           3 1027
01:00 dvdrw -> sr0 lrwxrwxrwx. 1 root root 3 1027 01:00 dvdrw1 -> sr1 lrwxrwxrwx. 1 root root 3 1027 01:00 fb -> fb0

b,c:裝置檔案

brw-rw----. 1 root cdrom    11,   0 1027 01:00 sr0
brw-rw----. 1 root cdrom    11,   1 1027 01:00 sr1
crw-rw----. 1 vcsa tty       7,   1 1027 01:00 vcs1
crw-
rw----. 1 vcsa tty 7, 2 1027 01:01 vcs2 crw-rw----. 1 vcsa tty 7, 3 1027 01:01 vcs3

p:管道檔案 特殊的檔案用於不同的程序間的傳遞

s:套接字檔案 用於網路不同的計算機程序通訊
p和s 沒搞懂 還要查詢資料
Linux目錄結構

  • / Linux檔案系統的入口
  • /bin 可執行二進位制檔案的目錄。例如ls,tar,cat
  • /boot
  • /dev
  • /etc 系統配置檔案
  • /home
  • /lib 存放系統使用的額函式庫
  • /mnt外部裝置掛接點
  • /proc用於提供系統的執行資訊
  • /root
  • /sbin 存放管理員可執行的命令 root可以使用的命令
  • /srv 服務啟動後要訪問的資料目錄
  • /tmp
  • /usr應用程式存放的目錄
  • /var存放系統經常變化的檔案
  • /lost+found 一些丟失的檔案可以在這裡找到
    絕對路徑 相對路徑 要知道是什麼
    檔案和目錄的屬性
    在這裡插入圖片描述
  1. i節點號
  2. 檔案型別
  3. 檔案許可權
  4. 連線計數 表明系統中有幾個檔案共用該檔案的inode,
  5. 檔案擁有者
  6. 檔案群組
  7. 檔案或目錄的大小
  8. 訪問或修改時間 這裡的是最後修改檔案內容的時間
    每個檔案或目錄都有9個許可權位每三個一組分別是擁有者,組群,其他
    在目錄中的檔案不管什麼許可權跟隨目錄的許可權

修改檔案和目錄的擁有者

       chown [-Rh] 檔案的新擁有者 檔名
       -R 遞迴
       -h 改變符號連結檔案的擁有者時不影響連結所指向的目標檔案

修改檔案和目錄的組群

       chgrp [-Rh] 檔案的新組群名 檔名
       -R 遞迴
       -h 改變符號連結檔案的擁有者時不影響連結所指向的目標檔案

修改檔案和目錄存取許可權

       chmod [-R] 檔名1 檔名2···
       -R 遞迴

許可權值 r 4 w 2 x1
檔案的隱藏屬性和預設許可權
chattr lsattr 預設許可權umask
檔案的特殊許可權除了 rwx 還有3個特殊的許可權 setuid , setgid ,stick bit
許可權中 s 普通使用者暫時有root許可權 ,t 指stick bit(貼上位)
setuid ,4 setgid 2 , stick bit 1
例如設定text檔案的特殊許可權
setuid:

#chmod 4755 text  
[[email protected] zhang]# chmod 4755 text
[[email protected] zhang]# ll
總用量 4
-rwsr-xr-x. 1 root  root     0 1027 02:41 text

setgid:

[[email protected] zhang]# chmod 2755 text
[[email protected] zhang]# ll
總用量 4
-rwxr-sr-x. 1 root  root     0 1027 02:41 text

stick bit:

[[email protected] zhang]# chmod 1755 text
[[email protected] zhang]# ll
總用量 4
-rwxr-xr-t. 1 root  root     0 1027 02:41 text 

hwclock -w 系統時間同步到硬體 -s 相反
常用的檔案和目錄管理指令命令

  • ls [-Radlrtupi] [目錄或檔名]
  • pwd
  • cd [目錄名]
  • mkdir
 mkdir [OPTION]... DIRECTORY...
DESCRIPTION
       Create the DIRECTORY(ies), if they do not already exist.
       Mandatory arguments to long options are mandatory for short
       options too.
       -m, --mode=MODE
              set file mode (as in chmod), not a=rwx - umask
       -p, --parents
              no error if existing, make parent directories as needed
       -v, --verbose
              print a message for each created directory
       -Z, --context=CTX
              set the SELinux security context of each created
              directory to CTX
       --help display this help and exit
       --version
              output version information and exit
  • mv
  • rm

檢視檔案內容的指令

  • cat
  • more [-cdflrsuw]
  • less
  • head
  • tail
  • nl [-bnw] nl命令讀取檔案(預設情況下讀取標準輸入),
  • tac 與cat相反最後一行先顯示 然後倒數第二行

查詢指令

  • which 可執行檔名
  • whereis [-bmsu] [BMS 目錄名 -f] 檔名 ##定位可執行檔案,原始碼檔案,幫助檔案在系統中的位置.
  • find [path] -option [-print] [-exec -ok command] {} ; ##要多學習多使用
  • locate [引數] [樣式] 配合資料庫檢視檔案位置

連結檔案 要會區分軟連線 硬連結區別
軟連結 指向目標檔案
硬連結 指向inode 不能誇分割槽
用ln 命令可建立連結檔案 -s 軟連結