linux零起点之---bash基础知识
linux零起点之—bash
- linux零起点之—bash
- bash的基础特性
- bash的基本工作特性之—- 命令历史
- 命令用法:
- 如何调用命令历史列表中的命令:
- 如何控制命令历史记录的方式:
- bash的基本工作特性之—-命令补全
- shell命令查找处理机制
- 目录管理类命令
- bash的基本工作特性之—-命令行展开功能
- bash的基本工作特性之—-命令的执行状态结果
- bash的基本工作特性之—-引用
- bash的基本工作特性之—快捷键
- bash的基本工作特性之—- 命令历史
- bash的基础特性
- 常用到的文件管理命令
- cat 命令
- tac 命令
- head 命令
- tail 命令
- more 命令
- less 命令
- cp 命令 : (copy)
- mv 命令 :(move)
- rm 命令 :(remove)
bash的基础特性
bash有很多的基础特性,能辅助我们更好的完成系统管理。
bash的基本工作特性之—- 命令历史
- 命令历史:shell进程会在其会话中保存在此前用户提交执行的命令。
history命令用于查看历史命令。在.bash.history文件中有一些常用的环境变量我们会使用得到,我们用这些环境变量来定制history的功能。
- HISTSIZE : 命令历史的条数(shell 的进程)
- HISTFILE : 持久保存命令历史文件
- HISTFILESIZE : 命令历史文件的大小
命令用法:
[OPTION]:
-c: clear ;清除历史命令记录。-d offset: ;(偏移量)删除。-r:从历史文件中读取命令历史到列表中。-w:从历史列表中的命令追加至历史文件中。#: 显示最近的#条命令。
例子:
[root@caibird ~]# history -w #保存历史记录到文件中
[root@caibird ~]# history 1 ls2 pwd3 clera4 clea。。。。。。中间省略。。。。。。69 ll `mkdir $(date +%F_%H_%M_%S)`70 clear71 history 372 history -w73 history
[root@caibird ~]# *****************************[root@caibird ~]# history -c #清除历史记录
[root@caibird ~]# history1 history
[root@caibird ~]# *****************************[root@caibird ~]# history 3 # 显示最近的3条命令69 ll `mkdir $(date +%F_%H_%M_%S)`70 clear71 history 3
[root@caibird ~]# *****************************[root@caibird ~]# history -r # 从文件中读取历史记录文件。
[root@caibird ~]# history 1 history2 history -r3 ls4 pwd5 clera6 clea7 clear 8 fdisk -l9 ls /proc/10 ls /proc/version*******中间省略********67 echo '$PATH'68 echo “$PATH”69 mkdir $(date +%F_%H_%M_%S)70 ll `mkdir $(date +%F_%H_%M_%S)`71 clear72 history 373 history -w74 history
[root@caibird ~]#
如何调用命令历史列表中的命令:
使用上,下方向键选择要执行的命令
!#:再一次执行历史列表中的第#条命令!!: 再一次执行上一次命令。!STRING:再一次执行命令历史中最近一个以STRING开始的命令。注意: 命令的重复执行有时候需要依赖于幂等性。
调用上次命令最后一个参数:
ESC ., 还有!$,ALT+.等等.
如何控制命令历史记录的方式:
环境变量:HISTCONTROL=” $STRING ” ;
$STRING有三种模式:- ignoredups:忽略重复的命令。
- ignorespace:忽略以上空白字符开头的命令。
- ignoreboth :既忽略重复的命令,又忽略以空白字符开头的命令。
- 修改变量的值: NAME=’VALUE’ # 只对当前SHELL有效。
bash的基本工作特性之—-命令补全
- shell程序在接收到用户执行命令的请求,分析完成之后,最左侧字符串会被当作命令。
shell命令查找处理机制
首先查找内部命令,再查找外面命令。如果没有找到,再根据PATH环境变量中设定的目录,自左向右逐个搜索目录下的文件夹。
补全机制:
文件补全:
给定的打头字符串如果能惟一标识某命令程序文件,则直接补全。
如果给定的打头字符的字符串不能惟一标识某命令程序文件,则再击一次Tab键一次,会给出列表。
路径补全:
- 根据给定的起始路径来补全,以对应路径下打头字符串逐一匹配起始路径下的文件。tab键一下,如果能惟一标识,则直接补全。否则,再按一次tab键,给出列表。
目录管理类命令
mkdir命令
- 功能 : 创建目录,make directory–>指定基名(basename)
常用选项
- -p : parent ; 自动按需创建目录,可以创建多层目录
- -v : verbose ; 显示创建的详细过程
- m : mode ; 直接给定权限
注意 :路径基名为命令的作用对角;基名之前的路径必须得存在。
例子:
[root@localhost test]# ls
[root@localhost test]# pwd
/tmp/test
[root@localhost test]# mkdir testdir
[root@localhost test]# ls
testdir
[root@localhost test]# ll
total 0
drwxr-xr-x. 2 root root 6 May 19 13:16 testdir
[root@localhost test]# *********************************[root@localhost test]# mkdir -pv ./testdir1/test2/test3/test4 #递归创建目录,并且显示创建过程。mkdir: created directory ‘./testdir1’
mkdir: created directory ‘./testdir1/test2’
mkdir: created directory ‘./testdir1/test2/test3’
mkdir: created directory ‘./testdir1/test2/test3/test4’
[root@localhost test]# tree ./testdir1
./testdir1
└── test2└── test3└── test43 directories, 0 files
[root@localhost test]#
rmdir命令
- 格式:rmdir [OPTION]… DIRECTORY…
- 功能:移除一个空目录
- 选项:
- -p : 删除某目录后,如果其父目录为空,则一并删除之
- -v :显示其删除过程
例子:
[root@localhost test]# ll -d ./testdir
drwxr-xr-x. 2 root root 6 May 19 13:16 ./testdir
[root@localhost test]# rmdir ./testdir
[root@localhost test]# ll -d ./testdir
ls: cannot access ./testdir: No such file or directory
[root@localhost test]# ls
testdir1
[root@localhost test]# ****************************[root@localhost test]# ls -dl testdir1/
drwxr-xr-x. 3 root root 19 May 19 13:18 testdir1/
[root@localhost test]# tree testdir1/
testdir1/
└── test2└── test3└── test43 directories, 0 files***************************
[root@localhost test]# rmdir -pv testdir1/ # 从最开始一层删除将会出现错误
rmdir: removing directory, ‘testdir1/’
rmdir: failed to remove ‘testdir1/’: Directory not empty
[root@localhost test]# tree testdir1/
testdir1/
└── test2└── test3└── test43 directories, 0 files***************************[root@localhost test]# rmdir -pv testdir1/test2/test3/test4/ #需要从最下一层的目删起
rmdir: removing directory, ‘testdir1/test2/test3/test4/’
rmdir: removing directory, ‘testdir1/test2/test3’
rmdir: removing directory, ‘testdir1/test2’
rmdir: removing directory, ‘testdir1’
[root@localhost test]#
bash的基本工作特性之—-命令行展
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
