2015年8月18日 星期二

RH124_02_檔案及目錄管理

1. Linux目錄配置













/
This is the system's root directory.
/root
This is the root account's home directory.
/home 
User home directories are located under this directory.
/etc
Configuration files specific to this system. This directory contains static, persistent system configuration data. For example: httpd
/run
Contains dynamic, non-persistent application runtime data.
/tmp
Temporary files are stored here. 
/usr
Contains installed software programs and libraries.
/usr/local
Locally customized software.  升級或額外安裝的程式擺放的目錄
/usr/bin
User commands. Regular user commands and utilities are located here. For example: ls, mv, rm
/usr/sbin
System administration commands. System administration binaries, for root use, are here. For example: fdisk, mount
/var
This directory contains dynamic configuration data, such as FTP and websites. 存放各種用途的log檔案。
/boot
Files needed in order to start the boot process. Kernel 及開機相關檔
/dev
Contains special device files which are used by the system to access hardware.

2. Locating Files by Name

查詢系統版本
$cat /etc/issue
$uname -r

顯示目前的目錄 pwd, print working directory

$pwd

切換目錄  
cd, change directory
$cd
$cd ~  回到自己的家目錄
$cd ~user  回到user的家目錄
$cd .  回到此層目錄
$cd ..  回到上層目錄
$cd -  回到上次去的目錄
$cd /home/student 切換到使用者的家目錄
[相對路徑|絕對路徑]

建立新目錄 mkdir, make directory

$mkdir dir1

刪除空目錄
 rmdir, remove directory
$rmdir dir1

列出目錄內容

$ls
-a  列出全部檔案,包含.開頭檔案
-l    列出檔名、許可權、所有者、檔案大小等詳細資訊
-R  列出所有子目錄層
-S  以檔案大小排序



3. Managing Files Using Command-Line Tools 
新建一個不存在的檔案或修改檔案的時間戳記
$touch
$touch file1  建立一個檔案file1時間戳記為現在時間
$touch file1 file2  將file1 file2的時間改成現在時間

拷貝檔案或目錄

$cp [來源檔] [目的檔] 拷貝來源檔到目的檔
$cp file1 file2  若目的檔已存在,會確認是否覆寫。
$cp -u file1 file2  若來源檔比較新或沒有目的檔才拷貝
$cp -r dir1 dir2  拷貝整個目錄。-r 針對目錄
$cp file1 file2 dir 拷貝多個檔案到目的目錄 

移動檔案或目錄

$mv file 1 file2 將 file1檔案名修改為 file2
$mv dir1 dir2   移動整個目錄 dir1到 dir2
$mv dir1 dir2  dir3 dir4 將目錄 dir1 dir2 dir3 整個移動到 dir4

移除檔案或目錄
$rm file1     刪除file1檔案,會確認是否刪除。
$rm -f file1  直接刪除file1檔案。-f 強制直接執行
$rm -r dir1   刪除目錄及目錄中的所有檔案,會一個個確認是否刪除。-r 針對目錄
$rm -rf dir1 直接刪除目錄及目錄中的所有檔案


4. Matching File Names Using Path Name Expansion





















新增glob目錄並新增10個檔案,並依照檔名字母順序列出檔案

$mkdir glob; cd glob
$touch alfa bravo charlie delta echo able baker cast dog easy
$ls
able alfa baker bravo cast charlie delta dog easy echo

列出a開頭檔案
$ls a*  
able alfa

列出名字有a的檔案

$ls *a* 
able alfa baker bravo cast  charlie delta easy

列出以a或c開頭檔案

$ls [ac]* 
able alfa cat  charlie

列出檔名四個字元的檔案
$ls ????
able alfa cast easy echo

列出檔名五個字元的檔案

$ls ?????
baker bravo delta

列出家目錄下glob目錄下的檔案

$ls ~/glob
able alfa baker bravo cast charlie delta dog easy echo
$echo ~/glob
/home/student/glob

顯示檔案

$echo {Sunday, Monday, Tuesday,Wednesday}.log
Sunday.log Monday.log Tuesday.log Wednesday.log
$echo file{1..3}.txt
file1.txt file2.txt file3.txt
$echo file{a..c}.txt
filea.txt fileb.txt filec.txt
$echo file{a,b}{1,2}.txt
filea1.txt filea2.txt fileb1.txt fileb2.txt
$echo file{a{1,2},b,c}.txt
filea1.txt filea2.txt fileb.txt filec.txt
$echo Today is `date +%A`.
Today is Wednesday.


沒有留言: