Linux bash基础特性
一、命令历史 环境变量
history命令用法: -d 删除指定的命令 -c 清空命令 -a 手工追加当前会话的命令历史到历史文件中去 ?调用历史命令 !#:重复执行第#条命令 !!:重复执行上一条命令 !str:执行指定str开头的命令(最后一个) ?控制命令历史的记录方式 主要和HISTCONTROL这个环境变量有关(”/etc/profile”) ignoredups:忽略重复 ignorespace:忽略空白开头 ignoreboth:上面2个都启用 二、命令补全 tab 三、路径补全 tab 四、目录管理类命令 1.mkdir 用法: mkdir [option] directoy… -p 没有父目录就一起创建了 -v 显示创建目录过程 -m 指定权限 [[email?protected] 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‘
[[email?protected] dirtest]# mkdir -m 0744 d
[[email?protected] dirtest]# ls
a d
[[email?protected] 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是文件,目标不存在 [[email?protected] dirtest]# touch a.tx
[[email?protected] dirtest]# ls
a a.tx bin d sbin usr x x_m x_n y_m y_n
[[email?protected] dirtest]# cp a.tx p
[[email?protected] 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存在 [[email?protected] dirtest]# cp a.tx p
cp: overwrite ‘p‘? y
[[email?protected] dirtest]# cp a.tx a
[[email?protected] 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不存在 [[email?protected] dirtest]# cp -r a ap
[[email?protected] 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
[[email?protected] 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存在 [[email?protected] dirtest]# cp -r a ap
[[email?protected] 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
[[email?protected] dirtest]# cd a
[[email?protected] a]# ls
a.tx b
[[email?protected] a]# tree ap
ap [error opening dir]
0 directories,0 files
[[email?protected] a]# ls
a.tx b
[[email?protected] a]# cd ..
[[email?protected] dirtest]# ls
a ap a.tx bin d p sbin usr x x_m x_n y_m y_n
[[email?protected] 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 递归
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |