命令别名

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. openstack项目【day24】:KVM部署

    本节内容 虚拟化支持 软件准备 检查CPU虚拟化支持 安装软件包 激活并启动libvirtd服务 网络模式 配置桥接网络 验证网络 尝试连接Hypervisor 创建虚拟机 虚拟机操作 一.虚拟化支持 ...

  2. 【转】史上最详细的Composer安装tp5教程

    http://www.thinkphp.cn/topic/52362.html Composer安装tp5教程1.下载composer先介绍几个网站Composer官网https://getcompo ...

  3. 模组 前后端分离CURD 组件

    js (function () { // {# -------------------------------------------------------------------------- # ...

  4. IDEA 中使用MyBatis-generator 自动生成MyBatis代码

    0.在Intellij IDEA创建maven项目 1. 在maven项目的pom.xml 添加mybatis-generator-maven-plugin 插件 <build> < ...

  5. Vue导出json数据到Excel表格

    一.安装依赖 npm install file-saver --save npm install xlsx --save npm install script-loader --save-dev 二. ...

  6. 【easy】110. Balanced Binary Tree判断二叉树是否平衡

    判断二叉树是否平衡 a height-balanced binary tree is defined as a binary tree in which the depth of the two su ...

  7. ROS-十步完成ROS-indigo安装

    Ubuntu 版本是14.04.5.(这个版本的ubuntu的内核是V4.4的内核,长期维护到2019年,是14代比较稳定的,反正用这个安装就没有什么依赖的头疼的问题,安装ROS很方便,可以去清华的网 ...

  8. 【算法】【python实现】二叉搜索树插入、删除、查找

    二叉搜索树 定义:如果一颗二叉树的每个节点对应一个关键码值,且关键码值的组织是有顺序的,例如左子节点值小于父节点值,父节点值小于右子节点值,则这棵二叉树是一棵二叉搜索树. 类(TreeNode):定义 ...

  9. SQL Server2016安装

    VS2017已经发布10多天了,这几天正好要重新做系统.所以想着把SQL Server和VS都做一次升级.VS2017只需要下载一个安装包就可以进行在线安装.但是SQL Server2016安装时会碰 ...

  10. liunx redis集群添加密码

    第一种方法: 修改每个节点redis.conf配置文件: masterauth 123456 requirepass 123456 各个节点的密码都必须一致,否则Redirected就会失败 重新启动 ...