linux命令总结(二)



一. vi 命令总结

vi +n filename :打开文件,并将光标置于第n行首

[root@ogg02 /]# vi +2 aaa.txt
hello world !!
hello zhengwei!!  光标在第二行,默认是第一行
this is a good man! 

vi + filename :打开文件,并将光标置于最后一行首

[root@ogg02 /]# vi + aaa.txt
hello world !!
hello zhengwei!!  光标在第二行,默认是第一行
this is a good man! 
| 光标在这个位置

vi +/pattern filename:打开文件,并将光标置于第一个与pattern匹配的串处
[root@ogg02 /]# vi +/zw aaa.txt
hello world !!
hello zhengwei!!
this is a good man!
zw 光标在这一行前面

vi -r filename :在上次正用vi编辑时发生系统崩溃,恢复filename

二:vi编辑器使用


gg:回到首行
G:到尾行
nG:到第n行
$:到行尾
^:到行首
fx:向右到第一个字符x处,x为任意字符
Fx:向左到第一个字符x处

从命令模式进入插入模式:
i:光标在当前位置进入插入模式
I:光标跳到行首并进入插入模式
a: 光变后退一个并进入插入模式
A:光变推到行尾并进入插入模式
o:在光标所在行下新起一行并进入插入模式
O:在光标所在行上新起一行并进入插入模式
s:删除光标所在字符并进入插入模式
S:删除光标所在行并进入插入模式

在vi中删除
x <del>:删除一个字符
2x:删除下2个字符
dd:删除当前行
dw:删至词尾(并不是删掉该词,因为光标可能不在单词第一个字符)
ndw:删除后n个词(分割符并不是默认的空格)
d$:删除至行尾
ndd:删除下n行

取消操作
u:取消上一个更改
U:取消一行内的所有更改
:e!:放弃所有更改,重新编辑(:e!代表先按:进入命令输入行再按e和!)

查找文本
/string:向下查找string
?string:向上超找string
n:继续查找下一个


命令模式的输入选项
:r /path/to/file  把/path/to/file的内容复制到光标处
:r !命令   把命令的结果插入到光标处
:!命令    执行命令,然后返回

退出、保存
:w 保存当前文件
:q 如果上次保存后没有修改,退出文件
:wq 保存退出
:q! 放弃保存退出


三. 显示文件命令

cat filename
more filename
head <-option> filename
    head -1  ;head –c -1
tail <-option> filename
    tail -1  ;tail –c -1
    tail -f

[root@ogg02 /]# head -1 aaa.txt   输出第一行
hello world !!
[root@ogg02 /]# head -2 aaa.txt   输出前两行
hello world !!
hello zhengwei!!

四.管道命令

  管道可以把一组命令按照数据流向的方式进行操作。简单地说,第一个命令执行后,不回显结果,而把结果通过管道传递给第二个命令。
第二个命令处理以后传递给第三个……直到没有管道符后才中止命令,并回显最终结果。
  管道命令很强大,可以使用不同的命令组合成强大的指令集合。比如,对文件夹下所有以txt结尾的文件重命名,就需要三个管道符号,四个命令完成。
 
五. wc 查看文件行数、字数命令


wc filename
wc –l filename查看文本文件行数。
wc –w filename查看文本文件字数。
wc –c filename查看文本文件字符数。

[root@ogg02 /]# wc -l aaa.txt
3 aaa.txt   --aaa.txt 有12行

[root@ogg02 /]# wc -w aaa.txt
10 aaa.txt   10  --一共有10个单词

[root@ogg02 /]# wc -c aaa.txt
52 aaa.txt     --aaa.txt 文件有52个字符

六. sort排序命令


格式:
sort <-option> filename
参数:
-n 以数字顺序排序
-r 倒序
-u 剔除重复
-k 指定排序的列,默认为第一列
-t 指定列间的分隔符,默认为空格。(不支持复杂分隔符,比如“::”)

[root@ogg02 /]# sort -r aaa.txt
this is a good man!
hello zhengwei!!
hello world !!
[root@ogg02 /]# sort -u aaa.txt
hello world !!
hello zhengwei!!
this is a good man!


七.tar 压缩命令

tar <-options> filename <file/directory>
-f 使用文件输入或者输出
-v 显示压缩过程
-z 加入zip压缩
-x 解压
-c 压缩
注意:-f参数必须有,不然会出现错误
Tar压缩命令常用于包含文件夹的压缩,比如整体项目的挪动。


范例一:将整个 /etc 目录下的文件全部打包成为 /tmp/etc.tar
[root@linux ~]# tar -cvf /tmp/etc.tar /etc<==仅打包,不压缩!
[root@linux ~]# tar -zcvf /tmp/etc.tar.gz /etc<==打包后,以 gzip 压缩
[root@linux ~]# tar -jcvf /tmp/etc.tar.bz2 /etc<==打包后,以 bzip2 压

解压命令
tar –xvf file.tar        //解压 tar包
tar -zxvf file.tar.gz    //解压tar.gz
tar -xjvf file.tar.bz2   //解压 tar.bz2
tar –xZvf file.tar.Z     //解压tar.Z

 
gzip 压缩命令
gzip filename
gunzip filename
gzip压缩常用于单个文件的压缩,比如:日志文件的压缩。


unzip -o -d /home/sunny myfile.zip
把myfile.zip文件解压到 /home/sunny/
-o:不提示的情况下覆盖文件;
-d:-d /home/sunny 指明将文件解压缩到/home/sunny目录下;


Linux压缩保留源文件的方法:
[root@ogg02 /]# gzip -c aaa.txt > aaa.gz --将 aaa.txt 压缩为 tmp.gz
-rw-r--r--  1 root   root     0 Feb  4 06:41 tmp.gz

Linux解压缩保留源文件的方法:
gunzip –c filename.gz > filename


八. find查找文件命令


按照文件名查找
find /home/training/ -name test  查找  /home/training/ 目录下的  test 文件
按照时间查找
find /home/training/  -type f -ctime -1
find /home/training/  -type d -cmin +1440 -name "dir2*“
执行后续操作
find ./ -mtime +30 -exec rm -rf {} \;

关机命令
shutdown –h  5
Shutdown –h now
Shutdown –k 5
reboot

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值