命令别名

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基础特性一的更多相关文章

  1. Linux bash基础特性二

    shell脚本的组成部分 shebang 各种命令组合 编程变量种类 本地变量: 仅仅在当前的shell生效 环境变量: 在当前和子shell生效 局部变量: shell进程某代码片段 位置变量: $ ...

  2. linux bash基础特性

    使用history命令,取得命令历史,当bash进程结束后,会把命令历史存放到文件中,下次开机还能看到命令历史. 定制history:通过设置环境变量,来定制history 环境变量$HISTSIZE ...

  3. linux bash基本特性

    一.bash 基础特性 (1)命令历史的功能 history: 环境变量 HISTSIZE:命令历史记录的条数 HISTFILE: ~/.bash_history 每个用户都有自己独立的命令历史文件 ...

  4. linux文件系统及bash基础特性

    linux文件系统 一.根文件系统 linux被识别的第一个被称为根之间关联的文件系统叫做根文件系统(rootfs),其他分区要想被读到,需要挂载到根目录的某个挂载点(根的子目录)上.根文件系统至关重 ...

  5. Bash 基础特性

    命令别名  alias 显示当前shell中定义的所有别名  alias 别名='原始命令'  unalias 别名 取消定义的别名在命令前加\使用命令本身,而不是别名(或者使用绝对路径执行命令使用命 ...

  6. bash基础特性3(shell编程)

    Linux上文本处理三剑客: grep:文本过滤工具 sed:stream editor,文本编辑工具 awk:文本报告生成器 grep -v:显示不能够被pattern匹配到的行 -i:忽略字符大小 ...

  7. bash基础特性2

    命令别名(alias) ()alias 显示当前shell进程所有可用的命令别名: ()alias NAME='VALUE' 定义别名NAME,相当于执行命令value ()unlias 撤销别名 注 ...

  8. bash基础特性1

    shell俗称壳(用来区别于内核),是指“提供使用者使用界面”的软件,就是一个命令行解释器. BASH是SHELL的一种,是大多数LINUX发行版默认的SHELL,除BASH SHELL外还有C SH ...

  9. 自学Linux Shell19.1-gawk程序基础特性

    点击返回 自学Linux命令行与Shell脚本之路 19.1-gawk程序基础特性 linux世界中最广泛使用的两个命令行编辑器: sed gawk 1. gawk概念 awk是一个强大的文本分析工具 ...

随机推荐

  1. Prometheus-配置解析

    1.Prometheus整体架构图 2.配置文件 # 全局配置 global: scrape_interval: 15s # 多久 收集 一次数据 evaluation_interval: 30s # ...

  2. CMDB服务器管理系统【s5day88】:采集资产-文件配置(二)

    上节疑问: 1.老师我们已经写到global_settings里了,为什么还要写到__init__.py setting 这的作用是为了:整合起两个的组合global_settings和setting ...

  3. Teamviewer远程ssh命令行更改密码启动

    Teamviewer远程ssh命令行更改密码启动 设置密码 $ sudo teamviewer passwd [NewPasswd ] 查看teamviewer信息 $ teamviewer info ...

  4. java集合分割

    java集合分割成等份的小集合: private <T> List<List<T>> getSubList(List list,int len) { if(list ...

  5. JS转换HTML转义符,编码及解码

    JS转换HTML转义符 //去掉html标签 function removeHtmlTab(tab) { return tab.replace(/<[^<>]+?>/g,'') ...

  6. 面试经验合集-Java后端<一>

    面试一:CDKHXJSYJS   时间:2018-12-29 周六 地点:航天科技大厦32楼   一 技术题目 <回忆版> 1.上下转型 2.Java异常:分类.处理.设计 3.二叉排序树 ...

  7. python数据结构之堆(heap)

    本篇学习内容为堆的性质.python实现插入与删除操作.堆复杂度表.python内置方法生成堆. 区分堆(heap)与栈(stack):堆与二叉树有关,像一堆金字塔型泥沙:而栈像一个直立垃圾桶,一列下 ...

  8. 《java与模式》

    2012年3月 随笔档案 - java_my_life - 博客园--此网友 12年的博客都是和模式有关的,希望可以多看看.http://www.cnblogs.com/java-my-life/ar ...

  9. webpack学习记录

    webpack 中文网站  https://webpack.docschina.org/ webpack1 有编译打包 模块热更新 代码分割 文件处理功能 webpack2 tree Shaking( ...

  10. JdbcTemplate中queryForObject方法返回空结果或不正确结果数量的解决方法

    在使用Spirng提供的JdbcTemplate中名为queryForObject API进行数据库查询时有时会抛出如下异常: org.springframework.dao.EmptyResultD ...