Linux bash基础特性一
命令别名
alias cdnet=”cd /etc/sysconfig/network-scripts”
针对用户的别名: “~/.bashrc”
针对系统的别名:”/etc/bashrc”
重读配置文件:source /path/to/config.file
unalias:撤销别名
glob通配
- * 代表任意长度的任意字符
- ?: 表示任意单个字符
- []:匹配指定范围的任意的单个字符
- [^]:取反
- [alnum]:所有字母和数字
- [:alpha:]:字母
- [:digit:]:数字
- [:lower:]:小写字母
- [:upper:]:大写字母
- [:punct:]:标点符号
- [:space:]:空白字符,不是仅仅空格
bash快捷键盘
- ctrl+L:
- ctrl+a:
- ctrl+e:
- ctrl+u:
- ctrl+k:
bash i/o重定向
- >
- >>:
- 2>
- 2>>
- > a.txt 2 > &1
- >>a.txt 2>> &1
命令历史
环境变量
- HISTSIZE:命令历史的条数
- HISTFILE:默认为’~/.bash_history’
- HISTFILESIZE:HISTFILE文件记录历史的条数
history命令用法:
-d 删除指定的命令
-c 清空命令
-a 手工追加当前会话的命令历史到历史文件中去
调用历史命令
!#:重复执行第#条命令
!!:重复执行上一条命令
!str:执行指定str开头的命令(最后一个)
控制命令历史的记录方式
主要和HISTCONTROL这个环境变量有关(”/etc/profile”)
ignoredups:忽略重复
ignorespace:忽略空白开头
ignoreboth:上面2个都启用
命令补全
tab
路径补全
tab
目录管理类命令
1.mkdir
用法: mkdir [option] directoy…
-p 没有父目录就一起创建了
-v 显示创建目录过程
-m 指定权限
[root@centos6 dirtest]# mkdir -pv /app/dirtest/a/b/c/d
mkdir: created directory '/app/dirtest/a'
mkdir: created directory '/app/dirtest/a/b'
mkdir: created directory '/app/dirtest/a/b/c'
mkdir: created directory '/app/dirtest/a/b/c/d'
[root@centos6 dirtest]# mkdir -m 0744 d
[root@centos6 dirtest]# ls
a d
[root@centos6 dirtest]# ll
total 8
drwxr-xr-x. 3 root root 4096 Aug 7 06:47 a
drwxr--r--. 2 root root 4096 Aug 7 06:47
2.tree
用法: tree [option] directory
-d 只显示目录
-L 只显示指定的level级别
-P 只显示匹配指定的路径
3.命令行展开
~,{},~username
4.命令的执行结果状态
$?:获取上一个命令的执行状态码
5.文件查看命令
more
less
head
-n 获取前n行
-c 获取前n个字符
tail
-n 获取后n行
-c 获取后n个字符
-f 动态显示
文件管理
用法: cp src dst
1.当src是文件,考虑dest是否存在
情况1:测试src是文件,目标不存在
[root@centos6 dirtest]# touch a.tx
[root@centos6 dirtest]# ls
a a.tx bin d sbin usr x x_m x_n y_m y_n
[root@centos6 dirtest]# cp a.tx p
[root@centos6 dirtest]# ll
total 40
drwxr-xr-x. 3 root root 4096 Aug 7 06:47 a
-rw-r--r--. 1 root root 0 Aug 7 07:09 a.tx
drwxr-xr-x. 2 root root 4096 Aug 7 07:01 bin
drwxr--r--. 2 root root 4096 Aug 7 06:47 d
-rw-r--r--. 1 root root 0 Aug 7 07:09 p
drwxr-xr-x. 2 root root 4096 Aug 7 07:01 sbin
drwxr-xr-x. 4 root root 4096 Aug 7 07:01 usr
drwxr-xr-x. 3 root root 4096 Aug 7 06:59 x
drwxr-xr-x. 2 root root 4096 Aug 7 07:00 x_m
drwxr-xr-x. 2 root root 4096 Aug 7 07:00 x_n
drwxr-xr-x. 2 root root 4096 Aug 7 07:00 y_m
drwxr-xr-x. 2 root root 4096 Aug 7 07:00 y_n
情况2:测试src是文件,dst存在
[root@centos6 dirtest]# cp a.tx p
cp: overwrite 'p'? y
[root@centos6 dirtest]# cp a.tx a
[root@centos6 dirtest]# ll a
total 4
-rw-r--r--. 1 root root 0 Aug 7 07:11 a.tx
drwxr-xr-x. 3 root root 4096 Aug 7 06:47 b
1.如果src是文件
(1)如果目标不存在:新建dest文件,并将src中的内容填充至dest中
(2)如果目标存在:
如果dest是文件:将src中的内容覆盖至dest中
如果dest是目录:在dest中新建与src同名的文件,将src中的文件内容填充至新文件中
情况3:测试src是目录,dst不存在
[root@centos6 dirtest]# cp -r a ap
[root@centos6 dirtest]# ll
total 44
drwxr-xr-x. 3 root root 4096 Aug 7 07:11 a
drwxr-xr-x. 3 root root 4096 Aug 7 07:12 ap
-rw-r--r--. 1 root root 0 Aug 7 07:09 a.tx
drwxr-xr-x. 2 root root 4096 Aug 7 07:01 bin
drwxr--r--. 2 root root 4096 Aug 7 06:47 d
-rw-r--r--. 1 root root 0 Aug 7 07:11 p
drwxr-xr-x. 2 root root 4096 Aug 7 07:01 sbin
drwxr-xr-x. 4 root root 4096 Aug 7 07:01 usr
drwxr-xr-x. 3 root root 4096 Aug 7 06:59 x
drwxr-xr-x. 2 root root 4096 Aug 7 07:00 x_m
drwxr-xr-x. 2 root root 4096 Aug 7 07:00 x_n
drwxr-xr-x. 2 root root 4096 Aug 7 07:00 y_m
drwxr-xr-x. 2 root root 4096 Aug 7 07:00 y_n
[root@centos6 dirtest]# ll a ap
a:
total 4
-rw-r--r--. 1 root root 0 Aug 7 07:11 a.tx
drwxr-xr-x. 3 root root 4096 Aug 7 06:47 b ap:
total 4
-rw-r--r--. 1 root root 0 Aug 7 07:12 a.tx
drwxr-xr-x. 3 root root 4096 Aug 7 07:12 b
情况4:测试src是目录,dst存在
[root@centos6 dirtest]# cp -r a ap
[root@centos6 dirtest]# ll ap
total 8
drwxr-xr-x. 3 root root 4096 Aug 7 07:14 a
-rw-r--r--. 1 root root 0 Aug 7 07:12 a.tx
drwxr-xr-x. 3 root root 4096 Aug 7 07:12 b
[root@centos6 dirtest]# cd a
[root@centos6 a]# ls
a.tx b
[root@centos6 a]# tree ap
ap [error opening dir] 0 directories, 0 files
[root@centos6 a]# ls
a.tx b
[root@centos6 a]# cd ..
[root@centos6 dirtest]# ls
a ap a.tx bin d p sbin usr x x_m x_n y_m y_n
[root@centos6 dirtest]# tree ap
ap
├── a
│ ├── a.tx
│ └── b
│ └── c
│ └── d
├── a.tx
└── b
└── c
└── d 7 directories, 2 files
由上可知:如果SRC是目录,则必须使用-r选项
(1)如果dest存在,则其必须使用目录,否则报错;现在dest目录创建与SRC同名的目录,并将SRC中所有的内容复制到dest中
(2)如果dest不存在,则先创建dest目录,并将SRC中所有的内容复制到dest目录中
mv
rm
i 交互
-f 强制
-r 递归
Linux bash基础特性一的更多相关文章
- Linux bash基础特性二
shell脚本的组成部分 shebang 各种命令组合 编程变量种类 本地变量: 仅仅在当前的shell生效 环境变量: 在当前和子shell生效 局部变量: shell进程某代码片段 位置变量: $ ...
- linux bash基础特性
使用history命令,取得命令历史,当bash进程结束后,会把命令历史存放到文件中,下次开机还能看到命令历史. 定制history:通过设置环境变量,来定制history 环境变量$HISTSIZE ...
- linux bash基本特性
一.bash 基础特性 (1)命令历史的功能 history: 环境变量 HISTSIZE:命令历史记录的条数 HISTFILE: ~/.bash_history 每个用户都有自己独立的命令历史文件 ...
- linux文件系统及bash基础特性
linux文件系统 一.根文件系统 linux被识别的第一个被称为根之间关联的文件系统叫做根文件系统(rootfs),其他分区要想被读到,需要挂载到根目录的某个挂载点(根的子目录)上.根文件系统至关重 ...
- Bash 基础特性
命令别名 alias 显示当前shell中定义的所有别名 alias 别名='原始命令' unalias 别名 取消定义的别名在命令前加\使用命令本身,而不是别名(或者使用绝对路径执行命令使用命 ...
- bash基础特性3(shell编程)
Linux上文本处理三剑客: grep:文本过滤工具 sed:stream editor,文本编辑工具 awk:文本报告生成器 grep -v:显示不能够被pattern匹配到的行 -i:忽略字符大小 ...
- bash基础特性2
命令别名(alias) ()alias 显示当前shell进程所有可用的命令别名: ()alias NAME='VALUE' 定义别名NAME,相当于执行命令value ()unlias 撤销别名 注 ...
- bash基础特性1
shell俗称壳(用来区别于内核),是指“提供使用者使用界面”的软件,就是一个命令行解释器. BASH是SHELL的一种,是大多数LINUX发行版默认的SHELL,除BASH SHELL外还有C SH ...
- 自学Linux Shell19.1-gawk程序基础特性
点击返回 自学Linux命令行与Shell脚本之路 19.1-gawk程序基础特性 linux世界中最广泛使用的两个命令行编辑器: sed gawk 1. gawk概念 awk是一个强大的文本分析工具 ...
随机推荐
- codeforces-1139 (div2)
A.如果第i个数字是偶数,总贡献就加上i #include <map> #include <set> #include <ctime> #include <c ...
- ArrayList的实现及原理
ArrayList ArrayList是最常见以及每个Java开发者最熟悉的集合类了,顾名思义,ArrayList就是一个以数组形式实现的集合,以一张表格来看一下ArrayList里面有哪些基本的元素 ...
- [物理学与PDEs]第5章习题5 超弹性材料中客观性假设的贮能函数表达
设超弹性材料的贮能函数 $\hat W$ 满足 (4. 19) 式, 证明由它决定的 Cauchy 应力张量 ${\bf T}$ 满足各向同性假设 (4. 7) 式. 证明: 若贮能函数 $W$ 满足 ...
- DUMP3.5 企业级电商项目
购物车模块 加入商品 更新商品数 查询商品数 移除商品 单选/取消 全选/取消 购物车列表 [浮点型商业运算精度丢失问题]ej1st 一书提到 float double只适合科研计算,BigDeci ...
- iPhone8再MacOS上修改手机铃声
1 选择下载好的mp3铃声文件,导入到itunes 2 将音乐改成AAA模式, 设置你的铃声时长 3 show in finder 找到文件,将mpr后缀修改成m4r,并删除掉mp3文件,将m4r文件 ...
- webpack构建Vue工程
先开始webpack基本构建 创建一个工程目录 vue-structure mkdir vue-structure && cd vue-structure 安装webpack ...
- https协议的简单理解
本片文章梳理三个知识点: 1.对称加密和非对称加密的区别 2.https协议的请求流程 3.http协议和https协议的区别 一.对称加密和非对称加密 对称加密:加密和解密使用同一密钥. 非对称加密 ...
- 分布式系列七: zookeeper简单用法
zookeeper是分布式开源框架, 是Google Chubby的一个实现, 主要作为分布式系统的协调服务. Dobbo等框架使用了其功能. zookeeper特性 顺序一致性: 事务请求最终会严格 ...
- 一些日期的计算方式 PHP
一些日期的计算 某个月内的所有天数: public function getMonthDay ($date) { $stattime = strtotime(date('Ym01',strtotime ...
- php in_array() 循环大量数组时效率特别慢问题
in_array() 会循环数组内部元素逐个匹配,特别耗时,换成以下方式,效率大大提升