- 一、内容查看
- 正序和反序输出cattac:
- 1、==cat==:显示文本内容
- 2、==tac==:显示文本内容(cat的倒序输出)
- 3、==cat 文件1 文件2 > 文件3==:文件合并
- 4、==cat -b==:显示行号输出
- 二、压缩、解压
- 常见用法:
- 1、==tar -zcvf<压缩文件><被压缩文件>==:打包及压缩(用得少)
- 2、==tar -zxvf==:解压
- 3、==tar -zxvf<压缩文件> -C <指定目录>== :解压到指定目录下(gzip包)
- 二、文件大小查看
- 常用操作:
- 1、==du -a==:统计全部目录及其子目录下的每个档案所占的磁盘空间
- 2、==du -h==: 统计全部目录及其子目录所占的磁盘空间
- 3、==du -ch==:统计对应目录及子目录所占空间并添加total
- 4、==du -sh==:直接统计总大小
- 三、vi编辑器
- 命令模式:
- 1、==dd==:删除所在行
- 2、==yyp==:复制粘贴
- 3、==999dd== :清空文件当前行下的所有内容
- 编辑模式:
- 末行模式:
- 1、==/abc==:按回车查找指定字符串,按n查找下一个
- 四、管道
- 常见用法:
- 1、==cat
| 命令 | 作用 |
|---|---|
| cat | 显示文本内容,类似Windows中的type(顺序输出) |
| tac | 显示文本内容(cat的倒序输出) |
| cat 文件1 文件2 > 文件3 | 文件合并 |
| cat -b | 显示行号输出 |
[root@hadoop60 ~]# ll 总用量 8 drwxrwxrwx. 2 root root 19 10月 7 13:13 aa drwxr-xr-x. 2 root root 19 10月 7 13:12 ab -rwxr-xr-x. 1 root root 0 10月 7 08:30 abc.txt lrwxrwxrwx. 1 root root 7 10月 7 09:48 abx.txt -> abc.txt -rw-------. 1 root root 1232 10月 5 08:58 anaconda-ks.cfg -rwxrwxrwx. 1 root root 6 10月 7 21:55 xyz.txt [root@hadoop60 ~]# cat xyz.txt 1 2 3 [root@hadoop60 ~]# tac xyz.txt 3 2 13、cat 文件1 文件2 > 文件3:文件合并
(1)举例:把abc.txt 和xyz.txt合并到b.txt 文件夹
(2)执行:
[root@hadoop60 ~]# ll 总用量 20 drwxrwxrwx. 2 root root 19 10月 7 13:13 aa drwxr-xr-x. 2 root root 19 10月 7 13:12 ab -rwxr-xr-x. 1 root root 6 10月 7 22:04 abc.txt lrwxrwxrwx. 1 root root 7 10月 7 09:48 abx.txt -> abc.txt -rw-------. 1 root root 1232 10月 5 08:58 anaconda-ks.cfg -rw-r--r--. 1 root root 6 10月 7 21:59 bac.txt -rw-r--r--. 1 root root 12 10月 7 22:05 b.txt -rwxrwxrwx. 1 root root 6 10月 7 21:55 xyz.txt [root@hadoop60 ~]# cat abc.txt 7 7 8 [root@hadoop60 ~]# cat xyz.txt 1 2 3 [root@hadoop60 ~]# cat abc.txt xyz.txt >b.txt [root@hadoop60 ~]# cat b.txt 7 7 8 1 2 34、cat -b:显示行号输出
举例:
[root@hadoop60 ~]# cat abc.txt
7
7
8
[root@hadoop60 ~]# cat -b abc.txt
1 7
2 7
3 8
注意:cat和more的区别:
查看大的文件用cat时会一次加载完。查看大的文件用more,用一次显示一屏幕,没有显示完时最后一行显示进度。回车显示下一行,按b显示上一页,空格显示下一页,q退出。
所以建议用more
| 命令 | 作用 |
|---|---|
| tar -zcvf | 打包及压缩(gzip方式) |
| tar -zxvf | 解压(gzip包) |
| tar -zxvf -C | 解压到指定目录下(gzip包) |
举例:压缩所有.txt结尾的文件到abc.tar.gz包里面,再ll查看发现有abc.tar.gz包了。
[root@hadoop60 ~]# ll 总用量 20 drwxrwxrwx. 2 root root 19 10月 7 13:13 aa drwxr-xr-x. 2 root root 19 10月 7 13:12 ab -rwxr-xr-x. 1 root root 6 10月 7 22:04 abc.txt lrwxrwxrwx. 1 root root 7 10月 7 09:48 abx.txt -> abc.txt -rw-------. 1 root root 1232 10月 5 08:58 anaconda-ks.cfg -rw-r--r--. 1 root root 6 10月 7 21:59 bac.txt -rw-r--r--. 1 root root 12 10月 7 22:06 b.txt -rwxrwxrwx. 1 root root 6 10月 7 21:55 xyz.txt [root@hadoop60 ~]# tar -zcvf abc.tar.gz *.txt abc.txt abx.txt bac.txt b.txt xyz.txt [root@hadoop60 ~]# ll 总用量 24 drwxrwxrwx. 2 root root 19 10月 7 13:13 aa drwxr-xr-x. 2 root root 19 10月 7 13:12 ab -rw-r--r--. 1 root root 222 10月 8 08:33 abc.tar.gz -rwxr-xr-x. 1 root root 6 10月 7 22:04 abc.txt lrwxrwxrwx. 1 root root 7 10月 7 09:48 abx.txt -> abc.txt -rw-------. 1 root root 1232 10月 5 08:58 anaconda-ks.cfg -rw-r--r--. 1 root root 6 10月 7 21:59 bac.txt -rw-r--r--. 1 root root 12 10月 7 22:06 b.txt -rwxrwxrwx. 1 root root 6 10月 7 21:55 xyz.txt2、tar -zxvf:解压
举例:复制压缩文件abc.tar.gz到ab目录下,查看ab目录发现还有另外一个文件,为了看得更直观,把a.txt删了,此时ab目录下只有压缩文件abc.tar.gz,执行命令,把abc.tar.gz解压,再查看ab目录下是解压完的文件。
执行:
[root@hadoop60 ~]# cp abc.tar.gz ab [root@hadoop60 ~]# ll ab 总用量 4 -rw-r--r--. 1 root root 222 10月 8 08:34 abc.tar.gz -rw-r--r--. 1 root root 0 10月 7 13:12 a.txt [root@hadoop60 ab]# rm -rf a.txt [root@hadoop60 ab]# ll 总用量 4 -rw-r--r--. 1 root root 222 10月 8 08:34 abc.tar.gz [root@hadoop60 ab]# tar -zxvf abc.tar.gz abc.txt abx.txt bac.txt b.txt xyz.txt [root@hadoop60 ab]# ll 总用量 20 -rw-r--r--. 1 root root 222 10月 8 08:34 abc.tar.gz -rwxr-xr-x. 1 root root 6 10月 7 22:04 abc.txt lrwxrwxrwx. 1 root root 7 10月 7 09:48 abx.txt -> abc.txt -rw-r--r--. 1 root root 6 10月 7 21:59 bac.txt -rw-r--r--. 1 root root 12 10月 7 22:06 b.txt -rwxrwxrwx. 1 root root 6 10月 7 21:55 xyz.txt [root@hadoop60 ab]#3、tar -zxvf<压缩文件> -C <指定目录> :解压到指定目录下(gzip包)
举例:
执行:
[root@hadoop60 ab]# cd ~ [root@hadoop60 ~]# ll 总用量 24 drwxrwxrwx. 2 root root 19 10月 7 13:13 aa drwxr-xr-x. 2 root root 97 10月 8 08:36 ab -rw-r--r--. 1 root root 222 10月 8 08:33 abc.tar.gz -rwxr-xr-x. 1 root root 6 10月 7 22:04 abc.txt lrwxrwxrwx. 1 root root 7 10月 7 09:48 abx.txt -> abc.txt -rw-------. 1 root root 1232 10月 5 08:58 anaconda-ks.cfg -rw-r--r--. 1 root root 6 10月 7 21:59 bac.txt -rw-r--r--. 1 root root 12 10月 7 22:06 b.txt -rwxrwxrwx. 1 root root 6 10月 7 21:55 xyz.txt [root@hadoop60 ~]# tar -zxvf abc.tar.gz -C aa abc.txt abx.txt bac.txt b.txt xyz.txt [root@hadoop60 ~]# ll aa 总用量 16 -rwxr-xr-x. 1 root root 6 10月 7 22:04 abc.txt lrwxrwxrwx. 1 root root 7 10月 7 09:48 abx.txt -> abc.txt -rwxrwxrwx. 1 root root 0 10月 7 13:13 a.txt -rw-r--r--. 1 root root 6 10月 7 21:59 bac.txt -rw-r--r--. 1 root root 12 10月 7 22:06 b.txt -rwxrwxrwx. 1 root root 6 10月 7 21:55 xyz.txt [root@hadoop60 ~]#
注:参数介绍:
| 参数 | 含义 |
|---|---|
| -z | 是否同时具有gzip的属性?亦即是否需要用gzip压缩? |
| -c | 创建一个压缩文件的参数指令(create的意思) |
| -x | 解开一个压缩文件的参数指令! |
| -v | 压缩的过程中显示文件 |
| -f | 使用档案名字,这个参数是最后一个参数,后面只能接档案名 |
简介:可以使用du命令统计文件和目录占用磁盘空间的情况。
常用操作:| 命令 | 作用 |
|---|---|
| du -a | 统计全部目录及其子目录下的每个档案所占的磁盘空间(统计所有) |
| du -h | 统计全部目录及其子目录所占的磁盘空间(只统计目录) |
| du -ch | 统计对应目录及子目录所占空间并添加total |
| du -sh | 直接统计总大小 |
[root@hadoop60 ~]# du -a 4 ./.bash_logout 4 ./.bash_profile 4 ./.bashrc 4 ./.cshrc 4 ./.tcshrc 4 ./anaconda-ks.cfg 4 ./.bash_history 0 ./abx.txt 4 ./ab/abc.tar.gz 4 ./ab/abc.txt 0 ./ab/abx.txt 4 ./ab/bac.txt 4 ./ab/b.txt 4 ./ab/xyz.txt 20 ./ab 0 ./aa/a.txt 4 ./aa/abc.txt 0 ./aa/abx.txt 4 ./aa/bac.txt 4 ./aa/b.txt 4 ./aa/xyz.txt 16 ./aa 4 ./xyz.txt 4 ./.ssh/known_hosts 4 ./.ssh 4 ./bac.txt 4 ./b.txt 4 ./abc.txt 4 ./abc.tar.g 88 . [root@hadoop60 ~]#2、du -h: 统计全部目录及其子目录所占的磁盘空间
执行:(1)通过du -h统计到了三个目录
[root@hadoop60 ~]# du -h 20K ./ab 16K ./aa 4.0K ./.ssh 88K .
(2)ll-a查看隐藏目录和文件,发现了这三个目录
[root@hadoop60 ~]# ll -a 总用量 48 dr-xr-x---. 5 root root 258 10月 8 08:33 . dr-xr-xr-x. 17 root root 224 10月 5 08:58 .. drwxrwxrwx. 2 root root 92 10月 8 08:39 aa drwxr-xr-x. 2 root root 97 10月 8 08:36 ab -rw-r--r--. 1 root root 222 10月 8 08:33 abc.tar.gz -rwxr-xr-x. 1 root root 6 10月 7 22:04 abc.txt lrwxrwxrwx. 1 root root 7 10月 7 09:48 abx.txt -> abc.txt -rw-------. 1 root root 1232 10月 5 08:58 anaconda-ks.cfg -rw-r--r--. 1 root root 6 10月 7 21:59 bac.txt -rw-------. 1 root root 835 10月 7 20:57 .bash_history -rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout -rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile -rw-r--r--. 1 root root 176 12月 29 2013 .bashrc -rw-r--r--. 1 root root 12 10月 7 22:06 b.txt -rw-r--r--. 1 root root 100 12月 29 2013 .cshrc drwx------. 2 root root 25 10月 7 15:06 .ssh -rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc -rwxrwxrwx. 1 root root 6 10月 7 21:55 xyz.txt
注:ll -a是列出当前目录下的所有文件(包括隐藏文件)
3、du -ch:统计对应目录及子目录所占空间并添加total(1)查看aa目录下所占的空间
[root@hadoop60 ~]# du -ch aa 16K aa 16K 总用量
(2)查看当前目录各自所占的空间及其总用量
[root@hadoop60 ~]# du -ch . 20K ./ab 16K ./aa 4.0K ./.ssh 88K . 88K 总用量4、du -sh:直接统计总大小
查看当前目录的总用量
[root@hadoop60 ~]# du -sh . 88K .三、vi编辑器
简介:
(1)安装完成的Linux系统通常都带有vi编辑器。
(2)vi总共有三种模式:命令模式、编辑模式、末行模式
简介:主要完成功能有删除、替换、撤销。
| 命令 | 作用 |
|---|---|
| dd | 删除所在行 |
| yyp | 复制粘贴 |
| 999dd | 清空文件当前行下的所有内容 |
(1)vi +文件,enter进入的是命令模式,这时连按两个d,就会删除所在行
[root@hadoop60 ~]# ll 总用量 24 drwxrwxrwx. 2 root root 92 10月 8 08:39 aa drwxr-xr-x. 2 root root 97 10月 8 08:36 ab -rw-r--r--. 1 root root 222 10月 8 08:33 abc.tar.gz -rwxr-xr-x. 1 root root 6 10月 7 22:04 abc.txt lrwxrwxrwx. 1 root root 7 10月 7 09:48 abx.txt -> abc.txt -rw-------. 1 root root 1232 10月 5 08:58 anaconda-ks.cfg -rw-r--r--. 1 root root 6 10月 7 21:59 bac.txt -rw-r--r--. 1 root root 12 10月 7 22:06 b.txt -rwxrwxrwx. 1 root root 6 10月 7 21:55 xyz.txt [root@hadoop60 ~]# vi xyz.txt
(2)进入了命令模式
1 2 3
(3)此时按dd就会删除所在行
2 32、yyp:复制粘贴
简介:光标定位在哪一行,按yyp就会复制所在行到下一行
2 2 33、999dd :清空文件当前行下的所有内容
简介:光标定位在哪一行,按999dd就会删除所在行下的所有内容(包括所在行),如果光标定位在第一行,按999dd就会删除所有内容。
编辑模式:| 命令 | 作用 |
|---|---|
| i | 进入编辑模式 |
| 命令 | 作用 |
|---|---|
| :wq | 保存文件,退出vi编辑器 |
| :w | 保存文件,但不退出vi编辑器 |
| :q | 不保存文件,退出vi编辑器 |
| : q! | 不保存文件,强制退出vi编辑器 |
| /abc | 按回车查找指定字符串,按n查找下一个 |
简介:
(1)vi +文件,enter进入命令模式,按Esc+/ +指定字符串,系统会从首位开始自动定位到该字符串
执行:
1 2 3 3 8 43 ~ ~ ~ /3
(2)此时再按n,系统会从上往下定位到下一个相同字符。
四、管道简介:管道命令使用|作为界定符号,管道命令需要结合其他命令一块使用
常见用法:1、cat test.txt | grep abc
输出test.txt文件中含abc的行(区分大小写,包含空格必须加引号)
2、cat test.txt | grep -i abc
输出test.txt文件中含abc的行(忽略大小写)
3、cat test.txt | grep -v abc
输出test.txt文件中不包含abc的行
注:管道命令尽量用cat,而不用more,因为more分页不太方便看。
(1)简介:查看文件里的内容,把文件里的abc过滤出来。
例:cat xyz.txt | grep 3 :把xyz.txt里的3过滤出来
[root@hadoop60 ~]# cat xyz.txt 1 2 3 [root@hadoop60 ~]# cat xyz.txt | grep 3 3
(2)注:要过滤的内容包含空格必须加引号
[root@hadoop60 ~]# cat xyz.txt | grep 3 4 grep: 4: 没有那个文件或目录 [root@hadoop60 ~]# cat xyz.txt | grep "3 4" 3 42、cat test.txt | grep -i abc:输出test.txt文件中含abc的行
输出test.txt文件中含abc的行(忽略大小写)
[root@hadoop60 ~]# cat xyz.txt | grep -i "d F" d f3、cat test.txt | grep -v abc: 输出test.txt文件中不包含abc的行
[root@hadoop60 ~]# cat xyz.txt 12 d f 1 17 3 4 2 3 [root@hadoop60 ~]# cat xyz.txt | grep -v "d f" 12 1 17 3 4 2 3五、统计
简介:wc主要用来计算文件的字数、字节数、行数。
| 命令 | 作用 |
|---|---|
| wc -l | 计算文件的行数 |
| wc -c | 计算文件的字符数 |
| wc -w | 计算单词数 |
| wc | 行数、单词数、字符数一起显示(显示顺序为行、单词、字符) |
(1)执行命令发现xyz.txt有7行
[root@hadoop60 ~]# wc -l xyz.txt 7 xyz.txt
(2)检查一下xyz.txt是不是7行:
[root@hadoop60 ~]# cat -b xyz.txt
1 12
2 d f
3 1
4 17
5 3 4
6 2
7 3
注:命令也可以写成cat xyz.txt | wc-l
2、wc -c:计算文件的字符数[root@hadoop60 ~]# wc -c xyz.txt 20 xyz.txt3、wc -w:计算单词数
[root@hadoop60 ~]# wc -w xyz.txt 9 xyz.txt4、wc:行数、单词数、字符数一起显示
[root@hadoop60 ~]# wc xyz.txt 7 9 20 xyz.txt
注:命令也可以写成cat xyz.txt | wc
六、查找 which命令含义:which查找$PATH中设置命令及安装文件目录所在位置。(查看命令所在位置)
[root@hadoop60 ~]# which pwd /usr/bin/pwd



