温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

shell中常用的vi编辑命令有哪些

发布时间:2021-11-08 13:36:33 来源:亿速云 阅读:382 作者:小新 栏目:建站服务器

这篇文章主要介绍shell中常用的vi编辑命令有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

1、常用的vi编辑命令

  • 模式切换

    shell中常用的vi编辑命令有哪些

  • 搜索:进入尾行模式, /关键词 回车自动匹配  按N键找寻下一个

  • 行号设置 :进入尾行模式  设置行号:set nu  取消行号:set nonu

  • 命令行模式常见的快捷键:
    dd:删除当前行
    dG:删除光标当前及以下的所有行
    ndd:删除光标当前及以下的n行
    gg:跳转到第一行的第一个字母
    G:跳转到最后一行的第一个字母
    shift+$ 行尾

  • 注意:刚进行命令行模式想进行粘贴文件内容时,一点要先按 i 键后再进行粘贴,否则会丢失文件内容;

  • 注意:编辑或者调优配置文件前,一定要进行备份

2、系统命令

  • 查看磁盘

[root@hadoop ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_hadoop-lv_root
                       50G  3.8G   43G   8% /
tmpfs                 996M     0  996M   0% /dev/shm
/dev/sda1             477M   42M  410M  10% /boot
/dev/mapper/vg_hadoop-lv_home
                       94G  2.3G   87G   3% /home
/dev/sr0              3.7G  3.7G     0 100% /mnt/cdrom
  • 查看内存  (扩展内容:http://blog.itpub.net/30089851/viewspace-2131678/)

[root@hadoop ~]# free -h
             total       used       free     shared    buffers     cached
Mem:          1.9G       691M       1.3G       256K        46M        74M
-/+ buffers/cache:       570M       1.4G 
Swap:         3.9G         0B       3.9G
  • 查看负载

[root@hadoop ~]# top
top - 23:04:17 up 14 min,  2 users,  load average: 0.04, 0.01, 0.00
Tasks: 150 total,   1 running, 149 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni, 99.9%id,  0.0%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:   2039008k total,   707992k used,  1331016k free,    47688k buffers
Swap:  4095996k total,        0k used,  4095996k free,    76636k cached
   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                           
   866 root      20   0     0    0    0 S  4.7  0.0   0:01.14 vmmemctl                                                           
    21 root      20   0     0    0    0 S  0.3  0.0   0:00.55 events/2                                                           
     1 root      20   0 19364 1536 1228 S  0.0  0.1   0:01.28 init                                                               
     2 root      20   0     0    0    0 S  0.0  0.0   0:00.01 kthreadd                                                           
     3 root      RT   0     0    0    0 S  0.0  0.0   0:00.01 migration/0
  • 案例:负载控制

[root@hadoop ~]# top
top - 23:04:17 up 14 min,  2 users,  load average: 0.04, 0.01, 0.00

    注意:负载均衡的数值不能超过10,即:load average: 0.04, 0.01, 0.00,后面这三个值别超过10,超过10表示当前机器繁忙

  • 举例:

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
   177   root       20       0       0          0       0      S    50%      70%     0:34.13    xxxx   去看看xxx这个进程是做什么
   1777  root      20       0       0          0       0      S   3908%   80%     0:34.13    hbase regionserver 

    上面案例描述中有两个问题

    (1)如果某服务长期占用cpu或者men,去检查这个进程是在做什么

    (2)如果cpu飙升3000%以上,夯住 ,代码级别,如果不是自己编写的代码,大概率硬件级别-->内存条坏了

              排查其他都没问题,重启机器吧

3、查看进程、查看端口号

  • 查看进程:ps -ef  查看这台服务器后台所运行的进程,可以使用管道符进行筛选,最后一条记录表示的当前的查询进程

[root@hadoop ~]# ps -ef | grep ssh
#进程用户 进程的pid 父id            进程用户的内容(进程所属的目录)
root       2081      1  0 22:49 ?        00:00:00 /usr/sbin/sshd
root       2367   2081  0 22:50 ?        00:00:00 sshd: root@pts/0 
root       2395   2081  0 22:54 ?        00:00:00 sshd: hadoop [priv]
hadoop     2397   2395  0 22:54 ?        00:00:00 sshd: hadoop@pts/1
root       2534   2369  0 23:38 pts/0    00:00:00 grep ssh
  • 过滤掉自己当前查询的进程: -v表示过滤

[root@hadoop ~]# ps -ef | grep ssh | grep -v grep
root       2081      1  0 22:49 ?        00:00:00 /usr/sbin/sshd
root       2367   2081  0 22:50 ?        00:00:00 sshd: root@pts/0 
root       2395   2081  0 22:54 ?        00:00:00 sshd: hadoop [priv]
hadoop     2397   2395  0 22:54 ?        00:00:00 sshd: hadoop@pts/1
  • 查看端口号:netstat -nlp 查询所有的端口号,结合grep筛选自己想要的端口号

[root@hadoop ~]# ps -ef | grep ssh | grep -v grep
root       2081      1  0 22:49 ?        00:00:00 /usr/sbin/sshd
root       2367   2081  0 22:50 ?        00:00:00 sshd: root@pts/0 
root       2395   2081  0 22:54 ?        00:00:00 sshd: hadoop [priv]
hadoop     2397   2395  0 22:54 ?        00:00:00 sshd: hadoop@pts/1
[root@hadoop ~]# netstat -nlp |grep 2397   #没有显示代表没有端口号
[root@hadoop ~]# netstat -nlp |grep 2081   #端口号:22
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      2081/sshd           
tcp        0      0 :::22                       :::*                        LISTEN      2081/sshd           
[root@hadoop ~]# netstat -nlp |grep 2395
[root@hadoop ~]#

        通过pid找port(端口号):因一个服务没有端口号都能运行
        1: 启动一个进程 ps 必须
        2: 可能启动一个port  netstat 不是必须

  • 在centos部署大数据组件,发现一个错误 Connection refused 

    (1)防火墙 web  iptables

        (2)ping ip 测试ip

        (3)telnet ip port 测试ip和端口号   (注:在Windows7 中telnet要单独部署,下面介绍命令部署)

  • 部署telnet命令

window  cmd黑窗口 不带 telnet命令 ,需要去安装一下 重启电脑

shell中常用的vi编辑命令有哪些

  • Linux部署Telnet命令

[root@hadoop ~]# yum install -y telnet
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.cn99.com
 * updates: mirrors.163.com
base                                                               | 3.7 kB     00:00     
extras                                                             | 3.4 kB     00:00  
...
Installed:
  telnet.x86_64 1:0.17-48.el6                                                             
Complete!
[root@hadoop ~]# which telnet
/usr/bin/telnet

4、高危命令

  • rm -rf /

  • vi 生产配置文件 100行 保存==》 cp xxx.xml xxx.xml20191117

  • kill -9 

kill -9 进程pid
kill -9 进程pid 进程pid 进程pid
kill -9 $(pgrep -f 匹配关键词)
ps 进程 xxx,top命令查询夯住的 / 删除xxx进程
杀进程之前,先ps 找到相关的进程,搞清楚,哪些是你要杀的,不然造成生产事故

5、安装yum软件

yum search xxx  #查找
yum install -y xxx-yyy  #安装  -y代表遇到判断yes/no 询问是 默认判断是yes
yum remove xxx-yyy #卸载

6、rpm包管理

[root@hadoop ~]# rpm -qa | grep http   #查看
httpd-tools-2.2.15-69.el6.centos.x86_64
httpd-2.2.15-69.el6.centos.x86_64
[root@hadoop ~]# rpm -e httpd-tools-2.2.15-69.el6.centos.x86_64   #卸载
[root@hadoop ~]# rpm -e  --nodeps  httpd-tools-2.2.15-69.el6.centos.x86_64  #强制卸载,不校验,直接删除

7、wget下载安装包

wget http://archive.cloudera.com/cdh6/cdh/5/hadoop-2.6.0-cdh6.16.2.tar.gz

8、压缩解压

  • 压缩

zip
zip -r xxx.zip ./*  在文件夹里面 
zip -r ruozedata.zip ruozedata/* 在外面
  • 解压

unzip ruozedata.zip
  • 大数据组件的压缩包几乎都是后缀 tar.gz

        tar -xzvf hadoop-2.6.0-cdh6.16.2.tar.gz

        tar -czvf hadoop-2.6.0-cdh6.16.2.tar.gz  hadoop-2.6.0-cdh6.16.2/*

Examples:
  tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.
  tar -tvf archive.tar         # List all files in archive.tar verbosely.
  tar -xf archive.tar          # Extract all files from archive.tar.

补充:清空这个内容

cat /dev/null > xxx.log 完美
echo '' > xxx.log 存在1个字节

以上是“shell中常用的vi编辑命令有哪些”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI