history 命令歷史,命令補全,別名
history 命令歷史
[root@binbinlinux ~]# echo $HISTSIZE 查看history 命令
1500
[root@binbinlinux ~]# !! 上一次的命令結果
echo $HISTSIZE
1500
[root@binbinlinux ~]# ls 12.txt
12.txt
[root@binbinlinux ~]# cat !$ !$¥執行上一次的命令結果
cat 12.txt
11111
11111
history 還可以指定第幾條命令 比如!987 他就會從 命令歷史裏從新執行這條命令
!c 就是從命令歷史查找最近的以C 開頭的命令 然後去執行
tab 鍵可以補全 例如 his按tab鍵就可補全
alias 別名
[root@binbinlinux ~]# alias ccc=‘cat 1.txt‘ 自定義別名
[root@binbinlinux ~]# alias 查看別名
alias ccc=‘cat 1.txt‘
alias cp=‘cp -i‘
alias l.=‘ls -d .* --color=auto‘
alias ll=‘ls -l --color=auto‘
alias ls=‘ls --color=auto‘
alias mv=‘mv -i‘
[root@binbinlinux ~]# unalias ccc 取消別名 unalias
[root@binbinlinux ~]# ccc 在次輸入報錯了
-bash: ccc: command not found
[root@binbinlinux ~]# ls *.txt *表示通配符 會把.txt的文件全部列出來
0.txt 123.txt 12.txt 1.txt 6.txt p.txt test.txt
[root@binbinlinux ~]# ls ?.txt 還可以用?號 匹配 一個字符 多位數匹配不到 1111
0.txt 1.txt 6.txt p.txt
[root@binbinlinux ~]# cat /etc/passwd |wc -l 管道符把這個命令丟給另一個命令 查看它的行
29
[root@binbinlinux ~]# cat /etc/passwd > 2.txt 重定向 > 會把原來的內容消失
[root@binbinlinux ~]# echo "dajslaksdjalksj" > 2.txt
[root@binbinlinux ~]# cat 2.txt 查看
dajslaksdjalksj
[root@binbinlinux ~]# echo "dajslaksdjalksj" >>2.txt 追加重定向
[root@binbinlinux ~]# echo "dajslaksdjalksj" >>2.txt
[root@binbinlinux ~]# cat 2.txt
dajslaksdjalksj
dajslaksdjalksj
[root@binbinlinux ~]# wc -l < 2.txt 反向重定向 把命令丟給 2.txt
3
[root@binbinlinux ~]# ls 1111 > 2.txt 正確重定向 只重定向正確的信息
ls: 無法訪問1111: 沒有那個文件或目錄
[root@binbinlinux ~]# ls 1111 2> 2.txt 2>也是正確重定向
[root@binbinlinux ~]# cat 2.txt
ls: 無法訪問1111: 沒有那個文件或目錄
[root@binbinlinux ~]# ls 1111 2>> 2.txt 追加錯誤重定向
[root@binbinlinux ~]# cat 2.txt
ls: 無法訪問1111: 沒有那個文件或目錄
ls: 無法訪問1111: 沒有那個文件或目錄
[root@binbinlinux ~]# sleep 100 ctrl +z 把一個命令暫停 Stopped
^Z
[1]+ Stopped sleep 100
[root@binbinlinux ~]# jobs 用jobs查看已經暫停的內容
[1]+ Stopped sleep 100
[root@binbinlinux ~]# sleep 122 sleep 是睡眠
^Z
[2]+ Stopped sleep 122
[root@binbinlinux ~]# jobs 查看哪些任務 內容
[1]- Stopped sleep 100
[2]+ Stopped sleep 122
[root@binbinlinux ~]# fg 掉到前臺來 fg
sleep 122
^Z
[2]+ Stopped sleep 122
[root@binbinlinux ~]# sleep 1222
^Z
[3]+ Stopped sleep 1222
[root@binbinlinux ~]# jobs
[1] Stopped sleep 100
[2]- Stopped sleep 122
[3]+ Stopped sleep 1222
[root@binbinlinux ~]# fg 帶+號的優先級更高一點 可以選擇數字 fg2 就是掉第二個
sleep 1222
^Z
[3]+ Stopped sleep 1222
[root@binbinlinux ~]# fg 2 掉第二個
sleep 122
^Z
[2]+ Stopped sleep 122
[root@binbinlinux ~]# bg bg 是後臺 調到後臺 帶&的
[2]+ sleep 122 &
[root@binbinlinux ~]# jobs
[1]- Stopped sleep 100
[2] Running sleep 122 &
[3]+ Stopped sleep 1222
[root@binbinlinux ~]# fg 2
sleep 122
^Z
[2]+ Stopped sleep 122
[root@binbinlinux ~]# bg
[2]+ sleep 122 &
[root@binbinlinux ~]# fg 2
-bash: fg: job has terminated
[2] Done sleep 122
本文出自 “11325852” 博客,請務必保留此出處http://11335852.blog.51cto.com/11325852/1982210
history 命令歷史,命令補全,別名