diff --git a/source/_posts/linux/1.1、linux常用命令与技巧(1).md b/source/_posts/linux/1.1、linux常用命令与技巧(1).md index eff9f99..21aed1b 100644 --- a/source/_posts/linux/1.1、linux常用命令与技巧(1).md +++ b/source/_posts/linux/1.1、linux常用命令与技巧(1).md @@ -81,6 +81,13 @@ cat data.z01 data.z02 data.zip > xdata.zip unzip xdata.zip ``` +执行`cat /dev/null`不会输出任何内容 +如果想要清空一个文件 +可以执行 +```bash +cat /dev/null > filename +``` + ### grep 全称是Global Regular Expression Print, 全局正则表达式输出 这个命令的作用是执行全文检索 diff --git a/source/_posts/linux/1.2、linux常用命令与技巧(2).md b/source/_posts/linux/1.2、linux常用命令与技巧(2).md new file mode 100644 index 0000000..28089ae --- /dev/null +++ b/source/_posts/linux/1.2、linux常用命令与技巧(2).md @@ -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` - 向后删除一个词(以空格隔开的字符串) + + +#### 快速获取历史命令 +按⬆️或者⬇️方向键可以快速切换到历史命令 +执行`history`可以看到当前shell执行过的历史命令 +![历史命令](/images/linux/history.png) +方向键也是在该列表当中查找的 +每一条历史命令都有一个对应的编号 + +`!编号`可以快速切换到该历史命令 +`!!` 两个感叹号代表切换到上一个命令, 这样也许不会比按⬆️键更方便 +但是却可以将当前输入的内容与历史命令进行结合 + +![叹号用法](/images/linux/exclamation.gif) + +叹号还有其他一些比较酷的用法, 可以截取历史命令的一部分 +感觉也不怎么容易记住, 就不赘述了 + +#### 目录快速切换 ++ `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` 执行结果发生变化时退出 diff --git a/source/images/linux/exclamation.gif b/source/images/linux/exclamation.gif new file mode 100644 index 0000000..bcb74f6 Binary files /dev/null and b/source/images/linux/exclamation.gif differ diff --git a/source/images/linux/history.png b/source/images/linux/history.png new file mode 100644 index 0000000..e949737 Binary files /dev/null and b/source/images/linux/history.png differ