• Linux常用命令详解(第三章)(ping、kill、seq、du、df、free、date、tar)


    本章命令(共7个):

    1 2 3 4 5 6 7 8
    ping kill seq du df free date tar

    1、" ping "

    作用:向网络主机发送ICMP(检测主机是否在线)

    ╭─root@localhost.localdomain ~  
    ╰─➤  ping -c 2 -w 5 -i 0.1 baidu.com   #-c 发送包的数量 ;-w  等待时间 ;-i  <间隔秒数>几秒发一个包;
    PING baidu.com (123.125.114.144) 56(84) bytes of data.
    64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=1 ttl=128 time=25.9 ms
    64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=2 ttl=128 time=49.9 ms
    
    --- baidu.com ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 100ms
    rtt min/avg/max/mdev = 25.991/37.979/49.968/11.990 ms
      
    

    2、" kill "

    作用:终止进程

    kill  PID
    kill -9        #强制终止     
    kill -15      #kill  默认kill -15    
    kill -l         #打印信号名列表
    

    3、" seq "

    作用:生成数列

    ╭─root@localhost.localdomain ~  
    ╰─➤  seq 4           #指定结束位置
    1
    2
    3
    4
    ╭─root@localhost.localdomain ~  
    ╰─➤  seq 3 7       #指定起始和结束位置
    3
    4
    5
    6
    7
    ╭─root@localhost.localdomain ~  
    ╰─➤  seq 3 3 14           #指定起始位置结束位置和步长
    3
    6
    9
    12
    
    

    4、" du "

    作用:输出文件及目录大小(文本占用磁盘块的大小 默认最小4k单位)

    -s或--summarize 仅显示总计

    常用选项:

    ╭─root@localhost.localdomain ~/2  
    ╰─➤  du -s /root          #仅显示总和
    9320	/root
    ╭─root@localhost.localdomain ~/2  
    ╰─➤  du -sh /root
    9.2M	/root                #人类易懂显示总和
    
    du 目录    #会默认显示一个目录下的所有的文件,最后一行会有大小的总和(可自行尝试);
    

    5、" df "

    作用:报告文件系统磁盘空间的使用情况

    ╭─root@localhost.localdomain ~/2  
    ╰─➤  df -h                  #-h 人类易懂的输出
    文件系统             容量  已用  可用 已用% 挂载点
    /dev/mapper/cl-root   17G  4.7G   13G   28% /
    devtmpfs             473M     0  473M    0% /dev
    tmpfs                489M  144K  489M    1% /dev/shm
    tmpfs                489M  7.1M  482M    2% /run
    tmpfs                489M     0  489M    0% /sys/fs/cgroup
    /dev/sda1           1014M  173M  842M   18% /boot
    tmpfs                 98M  8.0K   98M    1% /run/user/0
    /dev/sr0             4.1G  4.1G     0  100% /run/media/root/CentOS 7 x86_64
    
    • 第一列指定文件系统的名称
    • 第二列指定一个特定的文件系统1K-块1K是1024字节为单位的总内存。用和可用列正在使用中,分别指定的内存量。
    • 第三列使用列指定使用的内存的百分比
    • 而最后一列"安装在"指定的文件系统的挂载点。

    6、" free "

    作用:显示系统中已用和未用的内存空间总和

    常用选项:

    ╭─root@localhost.localdomain ~/2  
    ╰─➤  free -m         #以m为单位
                  total        used        free      shared  buff/cache   available
    Mem:            976         506          62           8         407         253
    Swap:          2047           0        2047
    ╭─root@localhost.localdomain ~/2  
    ╰─➤  free -h         #人类易读 (human)
                  total        used        free      shared  buff/cache   available
    Mem:           976M        504M         65M        8.5M        407M        256M
    Swap:          2.0G          0B        2.0G
    ╭─root@localhost.localdomain ~/2  
    ╰─➤  free -s 3         #-s <间隔秒数>  持续观察内存使用状况。
                  total        used        free      shared  buff/cache   available
    Mem:         999936      516164       66896        8704      416876      262392
    Swap:       2097148           0     2097148
    
                  total        used        free      shared  buff/cache   available
    Mem:         999936      516164       66896        8704      416876      262392
    Swap:       2097148           0     2097148
    
                  total        used        free      shared  buff/cache   available
    Mem:         999936      516164       66896        8704      416876      262392
    Swap:       2097148           0     2097148
    
    ^C                          #Ctrl + c  停止
    
    

    7、" date "

    作用: 打印或设置系统日期和时间

    常用选项:

    -s: 根据 STRING 设置时间
    
    %Y     年(用 4 位表示) (1970...)
    %m     月份(用两位表示) (01..12)
    %d     (月份中的)几号(用两位表示) (01..31)
    %H     小时(按 24 小时制显示,用两位表示) (00..23)
    %M     分钟数(用两位表示) (00..59)
    %S     秒数(用两位表示)(00..60)
    
    %T 时间,按 24 小时制显示(hh:mm:ss)
    
    %F 显示 %Y-%m-%d
    

    实例1:

    [root@fda ~]# date '+%F %T'
    2019-01-13 13:29:56
    

    实例2:

    [root@fda ~]# date -s "2019-01-13 13:30:00"
    Sun Jan 13 13:30:00 CST 2019
    [root@fda ~]# date
    Sun Jan 13 13:30:01 CST 2019
    

    8、tar

    常用组合:

    • 创建压缩归档:czvf
      v:显示过程细节
      z:有gzip属性的
    • 解压:xzvf (xf)
    • 查看tar包里的内容:tf
    ╭─root@localhost.localdomain ~/test  
    ╰─➤  touch file{1..35}
    ╭─root@localhost.localdomain ~/test  
    ╰─➤  ls
    file1   file13  file17  file20  file24  file28  file31  file35  file7
    file10  file14  file18  file21  file25  file29  file32  file4   file8
    file11  file15  file19  file22  file26  file3   file33  file5   file9
    file12  file16  file2   file23  file27  file30  file34  file6
    ╭─root@localhost.localdomain ~/test  
    ╰─➤  tar -cvzf file.tar.zg ./*
    ./file1
    ./file10
    ./file11
    ./file12
    ./file13
    ./file14
    ./file15
    ./file16
    ./file17
    ./file18
    ./file19
    ./file2
    ./file20
    ./file21
    ./file22
    ./file23
    ./file24
    ./file25
    ./file26
    ./file27
    ./file28
    ./file29
    ./file3
    ./file30
    ./file31
    ./file32
    ./file33
    ./file34
    ./file35
    ./file4
    ./file5
    ./file6
    ./file7
    ./file8
    ./file9
    ╭─root@localhost.localdomain ~/test  
    ╰─➤  ls
    file1   file13  file17  file20  file24  file28  file31  file35  file7
    file10  file14  file18  file21  file25  file29  file32  file4   file8
    file11  file15  file19  file22  file26  file3   file33  file5   file9
    file12  file16  file2   file23  file27  file30  file34  file6   file.tar.zg
    ╭─root@localhost.localdomain ~/test  
    ╰─➤  rm file{1..35}
    ╭─root@localhost.localdomain ~/test  
    ╰─➤  ls
    file.tar.zg
    ╭─root@localhost.localdomain ~/test  
    ╰─➤  tar -xzvf file.tar.zg ./
    ./file1
    ./file10
    ./file11
    ./file12
    ./file13
    ./file14
    ./file15
    ./file16
    ./file17
    ./file18
    ./file19
    ./file2
    ./file20
    ./file21
    ./file22
    ./file23
    ./file24
    ./file25
    ./file26
    ./file27
    ./file28
    ./file29
    ./file3
    ./file30
    ./file31
    ./file32
    ./file33
    ./file34
    ./file35
    ./file4
    ./file5
    ./file6
    ./file7
    ./file8
    ./file9
    ╭─root@localhost.localdomain ~/test  
    ╰─➤  ls
    file1   file13  file17  file20  file24  file28  file31  file35  file7
    file10  file14  file18  file21  file25  file29  file32  file4   file8
    file11  file15  file19  file22  file26  file3   file33  file5   file9
    file12  file16  file2   file23  file27  file30  file34  file6   file.tar.zg
    
    ╭─root@localhost.localdomain ~/test  
    ╰─➤#tar -tf httpd.tar
    httpd/
    httpd/apr-1.4.8-3.el7.x86_64.rpm
    httpd/apr-util-1.5.2-6.el7.x86_64.rpm
    httpd/httpd-2.4.6-40.el7.centos.x86_64.rpm
    httpd/httpd-tools-2.4.6-40.el7.centos.x86_64.rpm
    httpd/._httpd.conf
    httpd/httpd.conf
    httpd/._index.cgi
    httpd/index.cgi
    httpd/._index.html
    httpd/index.html
    httpd/install.sh
    httpd/mailcap-2.1.41-2.el7.noarch.rpm
    httpd/mod_ssl-2.4.6-40.el7.centos.x86_64.rpm
    
    
    #打时间包
    tar czf  file_$(data +%Y%m%d).tar.gz  /home/*
    

  • 相关阅读:
    个人作业——软件评测
    软件工程第五次作业——结对编程的实现
    软件工程第三次作业
    软件工程第一次作业
    两个矩形面积交
    二维并查集
    Java 作业 1
    练习题
    线性表

  • 原文地址:https://www.cnblogs.com/du-z/p/10822073.html
Copyright © 2020-2023  润新知