時間:
Linux時間 -- 系統時間;硬件時間
date:print or set the system date and time
[root@www ~]# date
2011年 07月 15日 星期五 00:01:53 CST
通用的設置格式:#date 月日時分年.秒
-s 設置指定字符串來分開時間
[root@www ~]# date 111111112011.11
2011年 11月 11日 星期五 11:11:11 CST
[root@www ~]# date -s 11/12/2011
2011年 11月 12日 星期六 00:00:00 CST
[root@www ~]# date -s 11:12
2011年 11月 12日 星期六 11:12:00 CST
clock(hwclock):query and set the hardware clock
通用的設置格式:hwclock/clock --set --date="月/日/年/ 時:分:秒"
clock -w (set the hardware clock to the current system time)
clock -s (set the system time from the hardware clock)
NTP(network time protocol) RTC(real-time clock)
cal :displays a calendar(顯示日曆)
cal [-smjy13] [[[day] month] year]
[root@www ~]# cal 5 10 2011(指定顯示2011/10/5)
FHS:filesystem hierarchy standard (文件系統目錄標準),多數Linux版本採用這種文件組織形式,類似於windows操作系統中c盤的文件目錄,FHS採用樹形結構組織文件。
FHS定義了兩層規範:第一層是根目錄(/)下面的各個目錄應該要放什麼文件數據,例如/etc應該要放配置文件等,第二層則是針對/usr和/var這兩個目錄的子目錄的定義,例如/var/log放置系統登錄文件、/usr/share放置共享數據等。
Linux的文件與目錄是樹形,這種目錄被稱爲目錄樹,它的特徵爲:1)目錄樹的起始點爲根目錄(/,root) 2)每個文件在此目錄樹中的文件名(包含完整路徑)是獨一無二的 3)每個文件或目錄的最大長度爲255個字符,完整路徑名稱及目錄的最大長度爲4096個字符 4)嚴格區分大小寫 5)不能使用/ 當文件名
絕對路徑:是從 / 開始的路徑
相對路徑:是從當前路徑開始的路徑
/boot:存放系統啓動的相關文件,如內核、initrd以及grub(bootloader)
/dev:存放的是設備與設備接口的文件,即設備文件,設備文件是Linux中特有的文件類型,在Linux系統中,以文件的方式訪問設備,即通過讀寫某個設備文件操作某個具體硬件。設備可分爲塊設備(可以隨機訪問設備,如硬盤)和字符設備(線性訪問設備,如鍵盤)
/etc:存放配置文件。一般來說,此目錄的各文件屬性是可以讓普通用戶查閱的,但是隻有root有權限修改
/home:用戶的家目錄,每一個用戶的家目錄通常默認爲/home/username
/root:root的家目錄
/lib:存放庫文件和內核模塊文件。動態庫的文件格式爲.so(shared object),靜態庫的文件格式爲.a
/media:掛載點目錄,用來臨時掛載光盤等移動設備
/mnt:掛載點目錄,額外的臨時文件
/opt:可選目錄,早期是第三方程序的安裝目錄
/proc:僞文件系統,內核映射文件,用來表示系統的運行狀態,也可以操作其中的文件控制系統
/sys:僞文件系統,跟硬件設備相關的屬性映射文件
/tmp:用來存放臨時文件
/var:存放的是可變的數據
/bin:binary-二進制,存放可執行的文件,用戶命令。該目錄下的命令可以被root與一般帳號使用,由於這些命令在掛接其它文件系統之前就可以使用,所以/bin目錄必須和根文件系統在同一個分區中
/sbin:該目錄下存放系統命令,即只有系統管理員(root)能夠使用的命令,系統命令還可以存放在/user/sbin/local/sbin(本地用戶自己安裝的系統命令放在這)目錄下,/sbin目錄存放的是最基本的系統命令,它們用於啓動系統和恢復系統等,與/bin目錄相似,在掛接其它文件系統之前就可以使用,所以/sbin目錄必須和根文件系統在同一個分區中
/usr:全局共享只讀文件,此目錄的內容可以存放在另一個分區中,裏面存放的是共享、只讀的程序和數據,目錄下的內容可以在多個主機共享
目錄管理:ls,cd,pwd,mkdir,rmdir,tree
ls:list directory contents
ls [option]...[file]...
-a 顯示目錄下的全部目錄和文件 包括隱藏文件,以"."開頭的文件表示隱藏文件,輸出顏色是藍色表示目錄, “.”表示當前目錄,“. ."表示父目錄
-A 顯示目錄下的全部目錄和文件 但不包含“.”“..”
-d 顯示目錄自身屬性
-i 顯示index number
-r 逆序顯示文件
-R 遞歸顯示
-h 做單位轉換
-l 長格式顯示
文件類型:
- : 普通文件
d : 目錄文件
b : 塊設備文件(block)
c : 字符設備文件(character)
l : 符號鏈接文件(symbolic link file)
p : 命令管道文件(pipe)
s : 套接字文件(socket)
文件權限(9位):每三位一組,每一組:rwx(讀寫執行)
文件硬鏈接次數
文件屬主(owner)
文件屬組(group)
文件大小(size),默認單位是字節(B)
時間戳(timestamp,最近一次被修改的時間,也就是修改時間戳):每個文件有三個時間戳,分別爲訪問時間戳(access),修改時間戳(modify,默認,文件內容發生改變),改變時間戳(change,元數據,屬性數據的改變)
文件名
cd : change the shell working directory
cd —— 直接切換到當前用戶的家目錄(home directory)
cd ~username ——切換到指定用戶的家目錄
cd - ——在當前目錄和前一次所在目錄之間來回切換
當前目錄和前一個目錄的變量保存查看
#echo $PWD
#echo $OLDPWD
"." 代表當前目錄
".." 代表父目錄
pwd: print name of current/working directory
pwd [option]...
mkdir: make directories
mkdir [option] ....directory
-v (verbose) print a message for each directory
-p (parents) no error if existing ,make parent directories as needed
-m (mode=MODE) set file mode (as in chmod),not a=rwx - umask ---------設置目錄權限
rmdir: remove empty directories(刪除空目錄)
rmdir [option]....directory...
-p (--parents) 刪除指定目錄及其上級空目錄
-v (--verbose) output a diagnostic for every directory processed(輸出處理的目錄詳情)
[root@www tmp]# rmdir test1/test2/test3/test4/ -pv
rmdir: 正在刪除目錄 "test1/test2/test3/test4/"
rmdir: 正在刪除目錄 "test1/test2/test3"
rmdir: 正在刪除目錄 "test1/test2"
rmdir: 正在刪除目錄 "test1
tree:顯示目錄結構
文件管理:touch,stat,file,rm,cp,mv
touch : change file timestamps(會建立一個空的目錄)
touch [option]....file....
-a change only the access time (僅修改access time)
-c (--no-create) do not create any files (僅修改文本的時間,若該文本不存在則部建立新文本)
-d (--date=string)parse string and use it instead of current time(可以跟欲修訂的日期而不用目前的日期,也可以使用 --date=“日期或時間”
-m change only the modification time
-t use[[CC]YY]MMDDhhmm[.ss] instead of current time(可以跟欲修訂的時間而不用目前的時間,格式爲[[CC]YY]MMDDhhmm[.ss] )
文本下有三個主要的時間參數,分別爲mtime,ctime,atime
modification time(mtime):當該文本的【內容數據】變更時,就會更新這個時間。內容數據指的是文本的內容,而不是文本的屬性或者權限。
change time(ctime):當該文本的【狀態(status)】改變時,就會更新這個時間,像是權限與屬性被更改了,都會更新這個時間。
access time (atime):當該文本被讀取時,就會更改這個訪問時間(access)。
stat : display file or file system status
stat [option]....file...
file : determine file type
可以查看文本的基本數據,比如是屬於ASCⅡ或者data文本,或者是binary,且其中有沒有使用動態函數庫(share library)等信息。
rm : remove files or directories
rm [option]....file
-f (--force) ignore nonexistent ,never prompt(強行刪除,忽略不存在的文本,不會出現告警提示)
-i prompt before every removal(交互,在刪除前會進行詢問是否刪除)
-r (-R ,--recursive)remove directories and their contents recursively (遞歸刪除)
root下 rm is aliased to 'rm -i '
/rm 忽略掉 alias的指定選項,代表本身
cp : copy files and directories
cp[option]...source...directory
-a (--archive) same as -dr --preserve=all(相當於 -pdr)
-d 若來源文件爲鏈接文件的屬性(link file),則複製鏈接文件屬性而非文件本身
-f (--force) if an existing destination file cannot opened,remove it and try again
-i (interactive) prompt before overwrite
-l (--link) link files instead of copying 進行硬式鏈接(hard link)的建立,而非複製文本本身
-p 連同文本的屬性一起復制過去,而非使用默認屬性(備份常用)
-r copy directories recursively 遞歸複製,用於目錄的複製行爲
-s (--symbolic-link) make symbolic links instead of copying (複製成爲符號鏈接文件,就是快捷方式文本)
-u 若destination比source舊才更新destination
如果source有兩個以上,則最後一個目的文件一定要【目錄】。
mv : move (rename) files
mv [option]...source....directory
-f do not prompt before overwriting
-i prompt before overwrite
-u 若目標文本已存在,且source比較新,纔會更新
練習:使用date單獨獲取系統當前的年份、月份、日、小時、分鐘、秒
年份:[root@www ~]# date +%Y
月份:[root@www ~]# date +%m
日 :[root@www ~]# date +%d
小時:[root@www ~]# date +%H
分鐘:[root@www ~]# date +%M
秒 :[root@www ~]# date +%S
創建 名爲/tmp/test1/test2/test3的目錄
# mkdir /tmp/test1/test2/test3 -p
[root@www /]# mkdir /tmp/test1/test2/test3 -pv
mkdir: 已創建目錄 "/tmp/test1"
mkdir: 已創建目錄 "/tmp/test1/test2"
mkdir: 已創建目錄 "/tmp/test1/test2/test3"
創建 名爲/tmp/test2 的目錄 並權限設爲rwx--x--x
[root@www /]# mkdir /tmp/test2/ -vm 711
mkdir: 已創建目錄 "/tmp/test2/"