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是一个强大的文本分析工具 ...
随机推荐
- <六>企业级开源仓库nexus3实战应用–使用nexus3配置yum私有仓库
一两个星期之前,你如果在我跟前说起私服的事情,我大概会绕着你走,因为我对这个东西真的一窍不通.事实上也正如此,开发同学曾不止一次的跟我说公司的私服版本太旧了,许多新的依赖编译之后不会从远程仓库自动缓存 ...
- C++(2):错误:undefined reference to `__gxx_personality_v0'
1. Linux Develop Notes * 编译 c++ 程序需要添加 -lstdc++ sample: gcc -lstdc++ -o test test.c,否则会报 " ...
- python14 1.带参装饰器 | wrapper 了了解 # 2.迭代器 ***** # 可迭代对象 # 迭代器对象 # for迭代器 # 枚举对象
## 复习 '''函数的嵌套定义:在函数内部定义另一个函数 闭包:被嵌套的函数 -- 1.外层通过形参给内层函数传参 -- 2.验证执行 开放封闭原则: 功能可以拓展,但源代码与调用方式都不可以改变 ...
- 集成学习—boosting和bagging
集成~bagging~权值~组合~抽样~样例~基本~并行 一.简介 集成学习通过构建并结合多个学习器来完成学习任务,常可获得比单一学习器显著优越的泛化性能 根据个体学习器的生成方式,目前的集成学习方法 ...
- Entity Framework入门教程(16)---Enum
EF DbFirst模式中的枚举类型使用 这一节介绍EF DbFirst模式中的Enum(枚举类型),CodeFirst模式中的Enum会在以后的EF CoreFirst系列中介绍.EF5中添加了对E ...
- JN_0001:在微信朋友圈分享时长大于10s的视频
1,先在聊天窗口里发送视频. 2,长按视频点击”收藏“. 3,进入微信收藏管理页面,播放视频. 4,点击右上角三点按钮,选择“转存为笔记”. 5,于是在收藏页面中会生成一个新的收藏笔记链接,打开链接再 ...
- 利用git提交代码
一.首先需要下载git 查看电脑是否安装git,打开终端,输入git,回车如果输出如下,则代表已安装了git 如果未安装,则会输出: 按照提示输入:sudo apt-get install git即可 ...
- [物理学与PDEs]第3章第1节 等离子体
1. 磁流体力学研究等离子体这种导电流体在电磁场中的运动. 2. 任何物质由于 $T, p$ 等条件的不同而可以处于固态.液态.气态 (常见的三种聚集态) 或等离子体. 3. 等离子体就是电离气 ...
- MVC控制器返回一个list 视图接收
控制器 public ActionResult InfoFrame() { List<Users> list = new List<Users>(); if (Session[ ...
- Django 实现list页面检索
在list.html写入from表单 在views渲染list方法写入,从前台获取的searchtitle根据name实现检索