2015年9月23日 星期三

Chapter 14. Accessing Linux File Systems.

  1. Storage management concepts

    Exceptions are hard drives in virtual machines, which typically show up as /dev/vd<letter> or /dev/xvd<letter>.
  2. Examining file systems

    # df 檔案或目錄名稱
    列出檔案系統的整體磁碟使用量

    -h:以 GBytes, MBytes, KBytes等格式顯示
    -H:以 M=1000K 取代 M=1024K 的進位方式

    # du 檔案或目錄名稱
    評估檔案系統的磁碟使用量

    -h:以 GBytes, MBytes, KBytes等格式顯示
     
  3. Mounting file systems manually

    # blkid
    列出裝置的 UUID 等參數
     
    # mount 裝置檔名 掛載點
    #
    mount UUID='' 掛載點
  4. Unmounting file systems

    # lsof
    列出被程序所開啟的檔案檔名
    由於檔案或目錄若於使用中,無法卸載,可用 lsof 指令確認

    # umount 掛載點
    卸載
     
  5. Accessing removable storage devices

    The mount point for the removable medium is /run/media/<user>/<label>.
     
  6. Managing links between files

    # ln [-sf] 來源檔 目標檔

    -s :如果不加任何參數就進行連結,那就是 hard link,至於 -s 就是symbolic link
    -f :如果 目標檔 存在時,就主動的將目標檔直接移除後再建立
     
  7. Locating files by name with locate

    # locate [-i] KEYWORD
    依據 /var/lib/mlocate 內的資料庫記載,找出使用者輸入的關鍵字檔名

    -i :忽略大小寫

    # updatedb
    根據 /etc/updatedb.conf 的設定去搜尋系統硬碟內的檔名,並更新 /var/lib/mlocate 內的資料庫檔案
     
  8. Searching for files with find

    # find / -name '*.txt'
    搜尋根目錄下,附檔名為 txt 的所有檔案

    # find /etc -name '*pass*'
    搜尋 etc 目錄下,檔案名稱內含 pass 的檔案

    # find / -iname '*message*'
    搜尋根目錄下,檔案名稱內含 message 的檔案,且忽略大小寫之分

    # find -user student
    搜尋屬於 student 的檔案
    也可以使用 -group, -uid, -gid

    # find /home -perm mode
    搜尋檔案權限『剛好等於 mode 的權限』的檔案

    # find /home -perm /mode
    搜尋檔案權限『包含任一 mode 的權限』的檔案

    # find /home -perm -mode
    搜尋檔案權限『必須要全部囊括 mode 的權限』的檔案

    # find size 10M
    搜尋檔案大小剛好 10M 的檔案

    # find -size +10G
    搜尋檔案大小大於 10G 的檔案

    # find -size -10k
    搜尋檔案大小小於 10k 的檔案

    # find / -mmin 120

    搜尋恰好在120分時修改的所有文件

    # find / -mmin +200
    搜尋200分以前修改的所有文件

    # find / -mmin -150
    搜尋在系統中最近150分鐘裡修改過的文件

    # find /etc -type TYPE
    搜尋檔案的類型為 TYPE 的,類型主要有:一般正規檔案 (f), 裝置檔案 (b, c), 目錄 (d), 連結檔 (l), socket (s), 及 FIFO (p) 等屬性