mv
mv file1 file2 重命名
mv file1 dir 移動文件
mv file1 file2 dir 移動多個文件
mv dir1 dir2 移動目錄,dir2不存在時爲重命名
-i 覆蓋確認
rm / rmdir
rmdir dir 只能刪除空目錄
rmdir dir1/dir2 逐層刪除
rm file1 刪除文件
rm file1 file2 刪除多個文件
rm –R dir 遞歸刪除目錄 -i 刪除確認
硬鏈接,符號鏈接
硬鏈接 :多個文件指向文件系統同一位置,修改其中一個所有的都被修改,刪除其中一個不會影響其他。
符號鏈接 : 與快捷方式相同。
ln
ln source target 建立硬鏈接
ln –s source target 建立符號鏈接(symbol)
ls -i
查看inode(文件索引節點)。
硬鏈接的文件inode相同。
man
man command 查看command的手冊
元字符(meta-characters)
* 與windows相同
? 與windows相同
[a-z] [ceg] 與RegEx相同
; 順序執行2個命令
> >> < 與windows相同 | 與windows相同
date
cal
cal [month [year]] 查看日曆
tee
tee file 將輸入流輸出到文件
ls | tee file -a Append
cat
cat file 查看文件內容
cat file1 file2 查看多個文件內容
awk / sort
略
cat file | awk –F, ‘{print $1 “/t” $3}’ | sort
more
more file1 分頁查看文件內容
ls | more 分頁查看其他命令輸出
head / tail
head -5 a.txt 查看前5行
tail -10 b.txt
vi
命令模式 / 輸入模式
h j k l 移動光標(同方向鍵)
^ $ 移動到行首和行尾
G 文件尾
#G 第#行。1G移動到文件頭
H M L 屏幕頭,中和尾
ctrl-f ctrl-b Forward and Backward
i a [到輸入模式] 當前光標處插入,當前光標後插入
o O [到輸入模式] 光標行下和上插入行
x 刪除字符
dw #dw 刪除當前詞,刪除多個詞
dd #dd 刪除當前行,刪除多行
:#,##d 刪除#到##行
r cw cc [到輸入模式]替換字符,單詞,行
C [到輸入模式]替換到行尾
yw yy 複製詞,行
dw dd 剪切詞,行
p 粘貼
:1,2co3 複製1,2行到第3行之後
:4,5m6 移動4,5行到第6行之後
:w [file] 存盤
:wq 存盤退出
:q! 不存盤退出
~ 改變大小寫
J 連接當前行和下一行
:# 移動到#行
/str ?str 向下,上查找str
n 繼續查找
:r file 插入文件
bash配置文件
~/.bash_profile
/etc/profile
users / who
列出所有已經登陸用戶
who am i / whoami
輸出當前登錄用戶信息
find
略
find path –name file
grep
grep str file 在file中尋找str,輸出包含str的行
ls –la | grep ‘str’
grep –x ‘regex’ file
-i 忽略大小寫
-v 輸出不符合條件的行
wc
wc 統計行數,單詞數和字符數
wc –l 統計行數
wc –w 統計單詞數
wc –C 統計字符數
du
disk-usage
ps
ps 列出進程
ps –ef 詳細
kill / pkill
kill pid 根據進程id kill進程
pkill pname 根據進程名kill進程
sleep
sleep # 當前進程sleep #秒
jobs
jobs 列出任務
fg / bg
fg # 將任務號爲#的任務前臺運行
bg # 將任務號爲#的任務後臺運行
任務號, not進程id
stop
stop pid 暫停任務(c shell)
ctrl-c ctrl-z
ctrl-c 終止前臺進程
ctrl-z 當前進程終止併到後臺,可用bg後臺運行
ping / ifconfig / netstat
ifconfig [-a] 與windows “ipconfig /all”類似
netstat –rn 輸出路由表
telnet / rlogin
telnet host port
rlogin host