1、目錄管理:
cd, pwd, ls 都是來查看目錄的node
mkdir: make directory 建立目錄
-p: 當指定的目標目錄的父目錄不存在時,則先建立之
-p, --parents
no error if existing, make parent directories as needed
-v, --verbose
print a message for each created directory 打印建立每一個目錄的信息
[root@linux_basic tmp]# mkdir hello
[root@linux_basic tmp]# ls
hello
[root@linux_basic tmp]# ls hello/
[root@linux_basic tmp]# mkdir how are
[root@linux_basic tmp]# ls
are hello how
rmdir: remove directory
rmdir - remove empty directories 刪除空目錄
-p: 刪除單傳目錄路徑中各空目錄
-p, --parents
remove DIRECTORY and its ancestors; e.g., ‘rmdir -p a/b/c’ is similar to ‘rmdir a/b/c a/b a’
[root@linux_basic tmp]# ls
are hello how
[root@linux_basic tmp]# rmdir are
[root@linux_basic tmp]# ls
hello how
[root@linux_basic tmp]# rmdir how
[root@linux_basic tmp]# ls
hello
[root@linux_basic tmp]# mkdir -pv test/apache/you
mkdir: created directory `test'
mkdir: created directory `test/apache'
mkdir: created directory `test/apache/you'
[root@linux_basic tmp]# ls
hello test you
[root@linux_basic tmp]# ls test/
apache
[root@linux_basic tmp]# rmdir test/apache -p
[root@linux_basic tmp]# ls
hello youlinux
bash的工做特色:沒有返回信息一般最好的信息
每一個命令執行結束後,會有一個「執行狀態返回值」,有效範圍0-255
0: 表示執行成功
1-255: 表示執行失敗apache
使用特殊變量$?能夠獲取最近一條命令的狀態返回值
# echo $?
[root@linux_basic tmp]# ls
hello
[root@linux_basic tmp]# echo $? 查看上一條命令的狀態返回值
0
[root@linux_basic tmp]# ls
hello
[root@linux_basic tmp]# rmdir are 目錄不存在,刪除報錯
rmdir: failed to remove `are': No such file or directory
[root@linux_basic tmp]# echo $?
1 轉態返回值不爲0windows
[root@linux_basic tmp]# ls
hello
[root@linux_basic tmp]# mkdir you/are
mkdir: cannot create directory `you/are': No such file or directory
[root@linux_basic tmp]# mkdir -p you/are 建立兩層的目錄
[root@linux_basic tmp]# ls
hello you
[root@linux_basic tmp]# ls you/
arebash
bash特性之一:命令行展開
~: 用戶家目錄
~USERNAME: 指定用戶的家目錄
[root@linux_basic tmp]# echo ~
/root
[root@linux_basic tmp]# ls /home/
cactiuser
[root@linux_basic tmp]# echo ~cactiuser
/home/cactiuser
{}: 有多個的話,每一個都會展開到對應項
/tmp/{x,y}
/tmp/x, /tmp/y網絡
/tmp/{x,y}/z
/tmp/x/z, /tmp/y/zapp
建立/tmp/x/z, /tmp/y/z, /tmp/x/m, /tmp/y/m
mkdir /tmp/{x,y}/{z,m}
練習1:建立/tmp/
a_b, c_b, a_d, c_d
[root@linux_basic tmp]# mkdir -pv {a,c}_{b,d}
mkdir: created directory `a_b'
mkdir: created directory `a_d'
mkdir: created directory `c_b'
mkdir: created directory `c_d' less
練習2:建立/tmp/mylinux/
boot
grub
bin
sbin
etc
rc.d
init.d
sysconfig
network-scripts
lib
modules
lib64
usr
local
bin
sbin
lib
lib64
bin
sbin
lib
lib64
proc
sys
dev
var
log
run
lock
tmp編輯器
# mkdir -pv /tmp/mylinux/{boot/grub,bin,sbin,etc/{rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,usr/{bin,sbin,lib,lib64,local/{bin,sbin,lib,lib64}},proc,sys,dev,var/{log,run,lock},tmp}
用tree能夠查看目錄的結構,安裝tree,yum install tree -y ;此時是須要有網絡的
2、文件查看和文件屬性信息
ls命令:
list簡寫
NAME
ls - list directory contentsui
SYNOPSIS
ls [OPTION]... [FILE]...
ls [option] [file]
經常使用選項:
-l: long,長格式顯示文件的詳細屬性信息
drwxr-xr-x. 2 root root 4096 Feb 12 09:55 account
左起第一位:文件類型
後面的9位:權限,常稱爲mode
r: 可讀,Read
w: 可寫, Write
x:可執行, eXcute
.: 表示文件有隱藏屬性
lsattr命令能夠查看隱藏屬性
數字:此文件被硬連接的次數,目錄通常都是2
屬主:owner, 文件的擁有者
屬組:group, 文件所屬的組
4096: 文件大小,單位是字節
-h: human-readable,自動作單位換算,打印大小
-h, --human-readable
with -l, print sizes in human readable format (e.g., 1K 234M 2G)
[root@linux_basic tmp]# ls -lh /tmp/
total 8.0K
drwxr-xr-x. 2 root root 4.0K Dec 20 14:01 hello
drwxr-xr-x. 3 root root 4.0K Dec 20 14:08 you
文件最近一次被修改的時間 文件名
-a: 顯示全部文件
-a, --all
do not ignore entries starting with .
[root@linux_basic tmp]# ls -a
. .. hello .ICE-unix you
-d: 一般和-l一塊兒使用,用於僅顯示目錄自身屬性
-d, --directory
list directory entries instead of contents, and do not dereference symbolic links
[root@linux_basic tmp]# ls -ld /tmp
drwxrwxrwt. 5 root root 4096 Dec 20 14:40 /tmp
-r: reverse, 逆序顯示 默認是升序顯示的
[root@linux_basic tmp]# ls
hello you
[root@linux_basic tmp]# ls -r
you hello
-R: recursive, 遞歸顯示,顯示子目錄中的內容
[root@linux_basic tmp]# ls -R
.:
hello you
./hello:
./you:
are
./you/are:
文件管理類的命令:
查看:cat, tac, head, tail, less, more
時間戳管理:touch
複製:cp
移動:mv
查看元數據屬性:stat
文本編輯器:nano, vi
stat: 顯示文件的元數據
時間戳:每一個文件都有三個時間戳
atime 訪問時間 最近一次被訪問的時間
mtime 修改時間 最近一次被修改的時間 文件內容的改變
ctime 改變時間 最近一次改變的時間 文件元數據的改變
[root@linux_basic tmp]# stat hello/
File: `hello/'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: fd00h/64768d Inode: 524365 Links: 2 被硬鏈接的次數
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-12-20 14:01:23.980000639 +0800 最近一次被訪問的時間
Modify: 2014-12-20 14:01:19.755999191 +0800 最近一次被修改的時間 文件內容的改變
Change: 2014-12-20 14:01:19.755999191 +0800 最近一次改變的時間 文件元數據的改變
inode(索引節點號,每一個文件都有索引節點,也叫元數據條目的編號)
[root@linux_basic tmp]# stat you/ 注意時間戳的改變
File: `you/'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: fd00h/64768d Inode: 524384 Links: 3
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-12-20 14:08:57.103000297 +0800
Modify: 2014-12-20 14:08:52.309009173 +0800
Change: 2014-12-20 14:08:52.309009173 +0800
[root@linux_basic tmp]# touch you/
[root@linux_basic tmp]# stat you/
File: `you/'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: fd00h/64768d Inode: 524384 Links: 3
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-12-20 14:55:18.363998749 +0800
Modify: 2014-12-20 14:55:18.363998749 +0800
Change: 2014-12-20 14:55:18.363998749 +0800
touch:改變文件的atime和mtime
NAME
touch - change file timestamps
SYNOPSIS
touch [OPTION]... FILE...
DESCRIPTION
Update the access and modification times of each FILE to the current time.
若是FILE不存在,默認會建立一個空文件
-a: 僅改變atime
-a change only the access time
-m: 僅改變mtime
-m change only the modification time
-c: 不建立空文件
-c, --no-create
do not create any files
-t [[CC]YY]MMDDhhmm[.ss] 指定那個時間修改和改變的
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
[root@linux_basic tmp]# stat test.txt
File: `test.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 524405 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-12-20 14:57:35.737999993 +0800
Modify: 2014-12-20 14:57:35.737999993 +0800
Change: 2014-12-20 14:57:35.737999993 +0800
[root@linux_basic tmp]# date
Sat Dec 20 15:15:42 CST 2014
[root@linux_basic tmp]# touch -a test.txt
[root@linux_basic tmp]# stat test.txt
File: `test.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 524405 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-12-20 15:15:56.177992895 +0800
Modify: 2014-12-20 14:57:35.737999993 +0800
Change: 2014-12-20 15:15:56.177992895 +0800
[root@linux_basic tmp]# touch -m test.txt
[root@linux_basic tmp]# stat test.txt
File: `test.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 524405 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-12-20 15:15:56.177992895 +0800
Modify: 2014-12-20 15:16:53.171995492 +0800
Change: 2014-12-20 15:16:53.171995492 +0800
[root@linux_basic tmp]# touch -a -t 201211091251.36 test.txt
[root@linux_basic tmp]# stat test.txt
File: `test.txt'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 524405 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-11-09 12:51:36.000000000 +0800
Modify: 2014-12-20 15:20:31.025993115 +0800
Change: 2014-12-20 15:22:44.780992659 +0800
文件查看類命令:
cat: 鏈接並顯示文本文件內容
NAME
cat - concatenate files and print on the standard output 鏈接文件和打印到標準輸出
SYNOPSIS
cat [OPTION]... [FILE]...
DESCRIPTION
Concatenate FILE(s), or standard input, to standard output.
數據流:stream
-E:顯示行結束符
-E, --show-ends
display $ at end of each line
-n: 顯示行號
-n, --number
number all output lines
[root@linux_basic tmp]# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m
[root@linux_basic tmp]# cat /etc/issue -n
1 CentOS release 6.6 (Final)
2 Kernel \r on an \m
3
[root@linux_basic tmp]# cat /etc/issue -E
CentOS release 6.6 (Final)$
Kernel \r on an \m$
$
Linux的換行符是$,windows下的換行符是$和回車符
tac: 逆序顯示文件內容
Shift+PageUp/PageDown: 翻屏,在虛擬終端上翻屏
分屏顯示:
more 和 less
more到文件尾部時,會自動退出
less到文件尾部時,不會自動退出,用q退出,和man的選項類似
查看首部或尾部的部份內容:
head 默認顯示頭10行
NAME
head - output the first part of files
SYNOPSIS
head [OPTION]... [FILE]...
tail 默認顯示尾部10行
-n #: 指定的行數,head和tail都支持此選項
[root@linux_basic tmp]# tail -5 /etc/inittab
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:
S0:12345:respawn:/sbin/agetty ttyS0 115200
tail -f -f, --follow[={name|descriptor}] output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent 監控一個尾部不斷變化的文件