命令别名

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. jmeter将上一个接口返回值作为下一个接口的请求参数

    在jmeter中有时候会用到,将上一个接口的返回值作为下一个接口的请求参数 具体操作如下: 1.首先新建一个http请求(右键线程组--添加Sampler--http请求),同时添加好接口相应的请求参 ...

  2. Quartz.net 3.x使用总结(一)——入门介绍

    1.Quartz.net简介 Quartz.NET是一个强大.开源.轻量级的任务调度框架.任务调度在我们的开发中经常遇到,如说:每天晚上三点让程序或网站执行某些代码,或者每隔5秒种执行一个方法等.Wi ...

  3. 类型和原生函数及类型转换(三:终结js类型转换)

    Number() parseInt() parseFloat() Boolean() String() toString() 一.显式类型转换 -------Number()函数把对象的值转换为数字. ...

  4. LFYZ-OJ ID: 1015 统计数字(NOIP2007)

    分析 本体思路很简单:读入数据,排序.统计.输出.难点在于数据量较大,选择何种排序方法就极为重要,否则很容易发生内存或时间超限.可以考虑以下几种思路: 桶排序 桶排序是可以想到的最简单方法,可在O(n ...

  5. JavaScript Date日期对象以及日期格式化方法

    前言 Date对象是javascript语言中内置的数据类型,用于提供日期和时间的操作接口.Date对象是在早期java中的java.util.Date类基础上创建的,为此,Date类型使用自UTC1 ...

  6. [再寄小读者之数学篇](2014-06-22 求极限 [中国科学技术大学2011年高等数学B考研试题])

    设数列 $\sed{x_n}$ 满足 $0<x_1<\pi$, $x_{n+1}=\sin x_n\ (n=1,2,\cdots)$. (1) 证明 $\dps{\vlm{n}x_n}$ ...

  7. 33. Springboot 系列 原生方式引入Redis,非RedisTemplate

     0.pom.xml <dependency> <groupId>redis.clients</groupId> <artifactId>jedis&l ...

  8. EffectiveC++ 第3章 资源管理

    我根据自己的理解,对原文的精华部分进行了提炼,并在一些难以理解的地方加上了自己的"可能比较准确"的「翻译」. Chapter 3 资源管理 条款13: 以对象管理资源 有时即使你顺 ...

  9. golang slice分割和append copy还是引用

    转载自:http://studygolang.com/articles/724 1. slice1:= slice[0:2] 引用,非复制,所以任何对slice1或slice的修改都会影响对方 dat ...

  10. 子级用了float浮动之后,如何撑开父元素,让父元素div自动适应高度

    方法一:对父级设置固定高度 假如以上案例,我们知道内部div高度100px,那对父级设置css height为100px看看效果. 此方法缺点,父级是固定高度,而不随内容高度自适应高度,没高度.此方法 ...