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


本文转自 amenging 51CTO博客,原文链接:http://blog.51cto.com/11335852/1982210

相关文章
|
15小时前
|
存储 安全 Linux
|
9月前
|
Linux
LINUX下用CTRL+R快速搜索HISTORY历史命令,快速索引到之前使用过的命令行语句
LINUX下用CTRL+R快速搜索HISTORY历史命令,快速索引到之前使用过的命令行语句
|
9月前
|
Linux Shell
一分钟学会变量,别名,历史命令,一行上执行两个命令,引号的使用
变量简单说就是让某一个特定字符串代表不固定的内容,变量可分为两类:环境变量(全局变量)和普通变量(局部变量
39 0
Linux Ctrl r 快速查询历史命令并查找符合条件的多条命令
Linux Ctrl r 快速查询历史命令并查找符合条件的多条命令
|
Linux
【Linux】命令别名与历史命令(alise\history)
【Linux】命令别名与历史命令(alise\history)
234 0
【Linux】命令别名与历史命令(alise\history)
禁止隐藏 history 命令,禁止执行某条命令
通过环境变量替换某条命令
510 0
|
Shell
history命令解析_学习笔记
时间:2017.11.13 作者:李强 参考:man,info,magedu讲义 声明:以下英文纯属个人翻译,英文B级,欢迎纠正,盗版不纠,才能有限,希望不误人子弟为好。 1、使用目的与场景     实现快速操作命令的一种方式 2、官方说明     Display or manipulate the history list. 3、写在前面     首先这里有两个概念history list和history file。
905 0