linux常用命令与技巧(2)
This commit is contained in:
parent
d3d66956ff
commit
7b7b39b21e
@ -81,6 +81,13 @@ cat data.z01 data.z02 data.zip > xdata.zip
|
|||||||
unzip xdata.zip
|
unzip xdata.zip
|
||||||
```
|
```
|
||||||
|
|
||||||
|
执行`cat /dev/null`不会输出任何内容
|
||||||
|
如果想要清空一个文件
|
||||||
|
可以执行
|
||||||
|
```bash
|
||||||
|
cat /dev/null > filename
|
||||||
|
```
|
||||||
|
|
||||||
### grep
|
### grep
|
||||||
全称是Global Regular Expression Print, 全局正则表达式输出
|
全称是Global Regular Expression Print, 全局正则表达式输出
|
||||||
这个命令的作用是执行全文检索
|
这个命令的作用是执行全文检索
|
||||||
|
|||||||
68
source/_posts/linux/1.2、linux常用命令与技巧(2).md
Normal file
68
source/_posts/linux/1.2、linux常用命令与技巧(2).md
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
---
|
||||||
|
title: 1.2、linux常用命令与技巧(2)
|
||||||
|
date: 2019-04-21 15:39:09
|
||||||
|
tags: linux
|
||||||
|
categories:
|
||||||
|
- linux
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 命令编辑及光标移动
|
||||||
|
|
||||||
|
+ `ctrl + a` - 光标移动到命令开头
|
||||||
|
+ `ctrl + e` - 光标移动到命令结尾
|
||||||
|
+ `alt + f` - 光标向前移动一个单词
|
||||||
|
+ `alt + b` - 光标向前移动一个单词
|
||||||
|
+ `ctrl + u` - 删除从开头到光标处的所有文本
|
||||||
|
+ `ctrl + k` - 删除从光标到结尾处的所有文本
|
||||||
|
+ `ctrl + w` - 向后删除一个词(以空格隔开的字符串)
|
||||||
|
<!-- more -->
|
||||||
|
|
||||||
|
#### 快速获取历史命令
|
||||||
|
按⬆️或者⬇️方向键可以快速切换到历史命令
|
||||||
|
执行`history`可以看到当前shell执行过的历史命令
|
||||||
|

|
||||||
|
方向键也是在该列表当中查找的
|
||||||
|
每一条历史命令都有一个对应的编号
|
||||||
|
|
||||||
|
`!编号`可以快速切换到该历史命令
|
||||||
|
`!!` 两个感叹号代表切换到上一个命令, 这样也许不会比按⬆️键更方便
|
||||||
|
但是却可以将当前输入的内容与历史命令进行结合
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
叹号还有其他一些比较酷的用法, 可以截取历史命令的一部分
|
||||||
|
感觉也不怎么容易记住, 就不赘述了
|
||||||
|
|
||||||
|
#### 目录快速切换
|
||||||
|
+ `cd -` 回到上一个目录
|
||||||
|
+ `cd`或者`cd ~`切换到当前用户的目录
|
||||||
|
|
||||||
|
#### 查看目录当中子目录的体积
|
||||||
|
`du -h -d 1`
|
||||||
|
-h 代表将大小转换为方便辨认的**K M G**等, 而不是现实字节数
|
||||||
|
-d 代表递归遍历的深度, 如果不加该参数则会递归遍历所有子目录
|
||||||
|
|
||||||
|
#### 复制粘贴
|
||||||
|
复制不能再是ctrl+c了,因为它表示终止当前进程,而控制台下的复制粘贴需要使用下面的快捷键
|
||||||
|
+ `ctrl + insert` 复制
|
||||||
|
+ `shift + insert` 粘贴
|
||||||
|
|
||||||
|
#### 实时查看文件
|
||||||
|
如果一个文件是被实时改变的
|
||||||
|
比如日志文件, 新写入的日志内容会追加到该文件的末尾
|
||||||
|
`tail`命令是查看文件末尾的若干行
|
||||||
|
```bash
|
||||||
|
tail -f filename.log
|
||||||
|
```
|
||||||
|
添加`-f`参数就可以实时显示文件内容了
|
||||||
|
|
||||||
|
#### watch命令
|
||||||
|
watch命令可以以固定时间反复执行某个命令, 以减少反复输入命令的操作
|
||||||
|
```bash
|
||||||
|
watch -n 2 cat test.txt
|
||||||
|
```
|
||||||
|
就表示每隔2秒执行一次**cat test.txt**
|
||||||
|
其他常用的参数
|
||||||
|
+ `-d` 高亮变化的内容
|
||||||
|
+ `-e` 指定的命令执行出错(退出码不是0)的时候终止定时执行
|
||||||
|
+ `-g` 执行结果发生变化时退出
|
||||||
BIN
source/images/linux/exclamation.gif
Normal file
BIN
source/images/linux/exclamation.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
BIN
source/images/linux/history.png
Normal file
BIN
source/images/linux/history.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Loading…
x
Reference in New Issue
Block a user