执行过的命令Linux都会记录,预设可以记录1000条历史命令。这些命令保存在用户的家目录的.bash_history文件中。只有当用户正常退出当前shell时,在当前shell中运行的命令才会保存至.bash_history文件中。

[root@lizhipeng01 ~]# history
1 ls -l .bash_history
2 vim /etc/profile
3 ls /root/.bash_history
4 cat /root/.bash_history
5 history

[root@lizhipeng01 ~]# echo $HISTSIZE       之前是1000,这个已经被我改了
10000

[root@lizhipeng01 ~]# history -c   当前命令历史清空

[root@lizhipeng01 ~]# history
1 history
[root@lizhipeng01 ~]# cat .bash_history

[root@lizhipeng01 ~]# history -c
[root@lizhipeng01 ~]# ls -l .bash_history
-rw-------. 1 root root 26957 1月 8 06:40 .bash_history

[root@lizhipeng01 ~]# vim /etc/profile            把它给成了5000

[root@lizhipeng01 ~]# echo $HISTSIZE       但是并没有生效
10000

[root@lizhipeng01 ~]# source /etc/profile     source一下,生效了
[root@lizhipeng01 ~]# echo $HISTSIZE

5000

[root@lizhipeng01 ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "
[root@lizhipeng01 ~]# echo $HISTTIMEFORMAT
%Y/%m/%d %H:%M:%S

打开另一个终端,没有生效。仅在当前终端生效。

[root@lizhipeng01 ~]# history
1 2018/01/09 07:39:08 ls -l .bash_history
2 2018/01/09 07:39:57 vim /etc/profile
3 2018/01/09 07:43:35 echo $HISTSIZE
4 2018/01/09 07:44:43 source /etc/profile
5 2018/01/09 07:44:49 echo $HISTSIZE
6 2018/01/09 07:48:01 HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "
7 2018/01/09 07:49:22 echo $HISTTIMEFORMAT
8 2018/01/09 07:54:59 history

[root@lizhipeng01 ~]# vim /etc/profile
[root@lizhipeng01 ~]# source /etc/profile

[root@lizhipeng01 ~]# chattr +a ~/.bash_history只会追加,不会删除,用户用的命令,都会被记录下来。

!!:连续两个!表示执行上一条指令。

!n:这里的n是数字,表示执行命令历史中的第n条指令。

!字符串:!pw表示执行命令历史中最近一次以pw开头的命令。

[root@lizhipeng01 ~]# yum install -y bash-completion

[root@lizhipeng01 ~]# rpm -qa bash-completion
bash-completion-2.1-6.el7.noarch

[root@lizhipeng01 ~]# alias restartnet='systemctl restart network.service'

[root@lizhipeng01 ~]# restartnet

[root@lizhipeng01 ~]# vi .bashrc  这个里面配置了几个alias

[root@lizhipeng01 ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias restartnet='systemctl restart network.service'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

[root@lizhipeng01 ~]# cd /etc/profile.d/                          alias定义在两个地方,一个是 /etc/profile.d/  ,另一个是.bashrc
[root@lizhipeng01 profile.d]# ls
256term.csh bash_completion.sh colorgrep.sh colorls.sh lang.sh less.sh vim.sh which2.sh
256term.sh colorgrep.csh colorls.csh lang.csh less.csh vim.csh which2.csh

通配符

*来匹配零个或多个字符,用?匹配一个字符

[root@lizhipeng01 ~]# ls
111 234 a.txt dir3 test4 testc.txt 学习计划安排.txt
123 2.txt.bak bb dir4 test5 Thinking_In_Java(中文版_第四版).pdf
1_hard.txt anaconda-ks.cfg dir2 split_dir testb.txt yum.log
[root@lizhipeng01 ~]# ls *.txt
1_hard.txt a.txt testb.txt testc.txt 学习计划安排.txt

[root@lizhipeng01 ~]# ls ?.txt
a.txt

[root@lizhipeng01 ~]# ls [0-3].txt
ls: 无法访问[0-3].txt: 没有那个文件或目录
[root@lizhipeng01 ~]# touch 1.txt 2.txt 3.txt
[root@lizhipeng01 ~]# ls [0-3].txt
1.txt 2.txt 3.txt

[root@lizhipeng01 ~]# ls [123].txt
1.txt 2.txt 3.txt

[root@lizhipeng01 ~]# ls {1,2}.txt
1.txt 2.txt
[root@lizhipeng01 ~]# ls {1,2,3}.txt
1.txt 2.txt 3.txt

输入输出重定向

[root@lizhipeng01 ~]# lsaaa 2> a.txt
[root@lizhipeng01 ~]# cat a.txt
-bash: lsaaa: 未找到命令

[root@lizhipeng01 ~]# lsaaa 2>> a.txt      追加
[root@lizhipeng01 ~]# cat a.txt
-bash: lsaaa: 未找到命令
-bash: lsaaa: 未找到命令

[root@lizhipeng01 ~]# ls [12].txt aaa.txt &> a.txt       &> 把正确和错误的信息输出定向到a.txt
[root@lizhipeng01 ~]# cat a.txt
ls: 无法访问aaa.txt: 没有那个文件或目录
1.txt
2.txt

[root@lizhipeng01 ~]# ls [12].txt aaa.txt &>> a.txt     追加
[root@lizhipeng01 ~]# cat a.txt
ls: 无法访问aaa.txt: 没有那个文件或目录
1.txt
2.txt
ls: 无法访问aaa.txt: 没有那个文件或目录
1.txt
2.txt

[root@lizhipeng01 ~]# ls [12].txt aaa.txt > 1.txt 2>a.txt       正确的定向到1.txt,错误的定向到a.txt
[root@lizhipeng01 ~]# cat 1.txt
1.txt
2.txt
[root@lizhipeng01 ~]# cat a.txt
ls: 无法访问aaa.txt: 没有那个文件或目录

[root@lizhipeng01 ~]# wc -l < 1.txt
2

转载于:https://www.cnblogs.com/sisul/p/8246452.html

8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向相关推荐

  1. 8.1shell介绍 8.2命令历史 8.3命令补全和别名 8.4通配符 8.5输入输出重定向

    8.1 shell介绍 . 查找一下有没有这2个安装文件 8.2 命令历史 环璄1000,所以只能存1000条记录 ' 有时候查到比1000多了,那是因为输入的命令还没有写进这个文件,只存在内存中 h ...

  2. 8.1-8.5 shell介绍,命令历史,命令补全和别名,通配符,输入输出重定向

    8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向 8.1 shell介绍 Linux Shell基础 介绍shell的特性,用法. shell是 ...

  3. shell介绍,命令历史,命令补全和别名 ,通配符, 输入输出重定向

    2019独角兽企业重金招聘Python工程师标准>>> shell介绍 shell是一个命令解释器,提供用户和机器之间的交互: 支持特定语法,比如逻辑判断.循环: 每个用户都可以有自 ...

  4. shell介绍 命令历史 命令补全和别名 通配符 输入输出重定向

    8.1 shell介绍 shell 是一个命令解释器,提供用户和机器之间的交互 支持特定语法,比如逻辑判断,循环 每个用户都可以有自己特定的shell CentOS7默认shell 为bash(Bou ...

  5. 8.1-5shell介绍 ,命令历史 ,命令补全和别名,通配符,输入输出重定向

    2019独角兽企业重金招聘Python工程师标准>>> Shell介绍 shell是一个命令解释器,提供用户和机器之间的交互 支持特定语法,比如逻辑判断.循环(if for whel ...

  6. mac git命令按tab键自动补全

    mac上命令行比windows好用很多,但是git默认按tab键是不会自动补全的,很不爽.下面我们按步骤来介绍怎么做到自动补全. 1.安装home-brew,相应大家装装过了,如果没装,直接去官网看下 ...

  7. linux命令行终端设置tab补全文件名或路径不区分大小写(大小写不敏感)

    在 inputrc 文件中增加一行配置 1 echo "set completion-ignore-case on">>~/.inputrc 当前用户重新登录后生效. ...

  8. Linux 基础命令包以及table自动补全包

    yum list bash-completion* yum -y install vim wget curl yum-utils bash-completion bash-completion-ext ...

  9. linux查看历史的所有命令,linux查询历史记录命令history的用法介绍

    一.什么是history在bash功能中,它能记忆使用过的命令,这个功能最大的好处就是可以查询曾经做过的举动! 从而可以知道你的运行步骤,那么就可以追踪你曾下达过的命令,以作为除错的工具! 二.His ...

最新文章

  1. 怎么查交集_胃镜要不要查?
  2. 48.动态分区匹配算法(连续分区)
  3. UA MATH563 概率论的数学基础 鞅论初步1 条件期望
  4. flash mini site Part 1 MUMA-新闻,演出系统
  5. csrf spring_无状态Spring安全性第1部分:无状态CSRF保护
  6. React开发(214):React中的Fragments
  7. 您需要来自pc的权限才能_微信电脑版还是鸡肋吗?微信PC版3.0内测体验
  8. bootstrap五星评分_如何用纯代码实现评分星级显示?
  9. mysql 外键_为什么大多数互联网公司不用外键约束
  10. mysql更新索引不影响业务_mysql 索引是否能提高UPDATE,DELETE,INSERT 处理速度
  11. EVENT:10218 dump uba of applied undo
  12. ContestHunter暑假欢乐赛 SRM 03
  13. 软件框架的理解(转载)
  14. 保障健康睡眠的几种食疗法
  15. 用递归法计算从n个人中选择k个人的组合数
  16. 64位ODBC数据源配置
  17. java速成 转载lvsi
  18. 第十届南京邮电大学网络攻防大赛(NCTF 2021)writeup
  19. 看单片机原理图-外部FLASHW25Q64
  20. WPF设置当前激活窗体(前景窗体)

热门文章

  1. java集合笔试编程题_Java 基础算法及编程笔试题集合
  2. 怎么引jsp包_电机引接线的制作流程防护等级
  3. python爱因斯坦的问题_爱因斯坦的思考题.py
  4. Java笔记-java web实现验证码
  5. Redis工作笔记-持久化
  6. C++工作笔记-C++代码实现接口的概念
  7. Qt文档阅读笔记-Object Trees Ownership解析与实例(为何某些程序在被关闭的时候会崩溃)
  8. Qt工作笔记-QML与C++交互
  9. linux网络状态检测libcurl,使用curl进行网络诊断 - msnshow的个人空间 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...
  10. 乐高无限无法连接到服务器,乐高无限近期热点问题FQ 新手问题解答