zoukankan      html  css  js  c++  java
  • linux系统管理命令

    系统管理命令


    ps aux 查看所有详细后台的进程

    操作系统:管理硬件软件资源的应用程序。

    进程:有资格从操作系统申请资源。

    守护进程:在后台运行的进程,没有终端控制的进程,反之为 非守候进程。

    [zyj@localhost home]$ tail -f 1.txt
    dfdfsdfsf
    
    [zyj@localhost ~]$ ps aux | grep tail
    zyj        3157  0.0  0.0 100964   608 pts/2    S+   09:54   0:00 tail -f 1.txt
    zyj        3161  0.0  0.0 103304   744 pts/1    S+   09:54   0:00 grep tail

    ps :命令查看系统进程的详细状况;

    -a :显示终端上所有进程,包括其他用户的进程

    -u:显示进程的详细状态

    -x:显示没有控制终端的进程

    -w:显示加宽,以便显示更多信息

    -r:只显示正在运行的进程

    [zyj@localhost home]$ ps au
    USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root       2483  0.0  0.0   4068   544 tty2     Ss+  09:43   0:00 /sbin/mingetty /dev/tty2
    root       2485  0.0  0.0   4068   540 tty3     Ss+  09:43   0:00 /sbin/mingetty /dev/tty3
    root       2487  0.0  0.0   4068   540 tty4     Ss+  09:43   0:00 /sbin/mingetty /dev/tty4
    root       2489  0.0  0.0   4068   544 tty5     Ss+  09:43   0:00 /sbin/mingetty /dev/tty5
    root       2491  0.0  0.0   4068   540 tty6     Ss+  09:43   0:00 /sbin/mingetty /dev/tty6
    root       2513  0.5  2.8 176352 29116 tty1     Ss+  09:43   0:04 /usr/bin/Xorg :0 -br -verbose -audit 4 -auth /var/run/gdm/auth-fo
    zyj        2928  0.0  0.1 108336  1684 pts/0    Ss+  09:45   0:00 /bin/bash
    zyj        2949  0.0  0.1 108364  1812 pts/1    Ss+  09:45   0:00 -bash
    zyj        3130  0.0  0.1 108364  1840 pts/2    Ss   09:53   0:00 -bash
    zyj        3219  0.0  0.1 110232  1068 pts/2    R+   09:57   0:00 ps au

     top:监控操作系统的运行情况,非守护进程,由终端控制,按q退出。

    [zyj@localhost ~]$ top
    top - 09:59:34 up 16 min,  4 users,  load average: 0.27, 0.17, 0.11
    Tasks: 153 total,   1 running, 152 sleeping,   0 stopped,   0 zombie
    Cpu(s):  0.3%us,  0.7%sy,  0.0%ni, 97.0%id,  2.0%wa,  0.0%hi,  0.0%si,  0.0%st
    Mem:   1004112k total,   907020k used,    97092k free,     8272k buffers
    Swap:  2031612k total,        8k used,  2031604k free,   607472k cached
    
       PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                             
        24 root      20   0     0    0    0 S  0.3  0.0   0:00.27 ata_sff/0                                                            
      2948 zyj       20   0 99.7m 1856  860 S  0.3  0.2   0:00.09 sshd                                                                 
      3259 zyj       20   0 15036 1280  948 R  0.3  0.1   0:00.14 top                                                                  
         1 root      20   0 19352 1416 1096 S  0.0  0.1   0:01.98 init                                                                 
         2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                                                             
         3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                          
         4 root      20   0     0    0    0 S  0.0  0.0   0:00.04 ksoftirqd/0                                                          
         5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/0                                                            
         6 root      RT   0     0    0    0 S  0.0  0.0   0:00.01 watchdog/0       

     kill:杀死一个进程。

    [zyj@localhost home]$ tail -f 1.txt 
    dfdfsdfsf
    
    
    [zyj@localhost home]$ ps aux | grep tail
    zyj        3316  0.0  0.0 100964   608 pts/1    S+   10:01   0:00 tail -f 1.txt
    zyj        3324  0.0  0.0 103304   744 pts/2    S+   10:02   0:00 grep tail 
    [zyj@localhost home]$ kill -9 3316
    
    [zyj@localhost home]$ tail -f 1.txt 
    dfdfsdfsf
    Killed
    [zyj@localhost home]$ 
    [zyj@localhost home]$ tail -f 1.txt 
    dfdfsdfsf
    
    [zyj@localhost home]$ ps aux | grep tail
    zyj        3361  0.0  0.0 100964   608 pts/1    S+   10:04   0:00 tail -f 1.txt
    zyj        3363  0.0  0.0 103304   748 pts/2    S+   10:04   0:00 grep tail
    [zyj@localhost home]$ killall tail
    [zyj@localhost home]$ ps aux | grep tail
    zyj        3372  0.0  0.0 103304   748 pts/2    S+   10:04   0:00 grep tail

    系统关机重启命令:

    reboot、shutdown、init

    查看磁盘相关命令


     df:查看磁盘分区及空间大小;任何设备使用需要挂载。

    [zyj@localhost home]$ df
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       18208184 3243892  14032708  19% /
    tmpfs             502056      80    501976   1% /dev/shm
    /dev/sda1         289293   35725    238208  14% /boot

    增加一个磁盘:分区、挂载、格式化。

    先在虚拟机上增加一个磁盘;

    [root@localhost ~]# fdisk -l  //查看磁盘信息
    
    Disk /dev/sda: 21.5 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00093a1f
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          39      307200   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              39        2358    18631680   83  Linux
    /dev/sda3            2358        2611     2031616   82  Linux swap / Solaris
    [root@localhost ~]#  
    [root@localhost ~]# init 6  //关机重启后识别刚才添加的磁盘,冷启动,关电重启。
    [root@localhost dev]# ls sd*
    sda  sda1  sda2  sda3  sdb
    [root@localhost dev]# fdisk /dev/sdb   //创建分区
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel with disk identifier 0x0c4df6a2.
    Changes will remain in memory only, until you decide to write them.
    After that, of course, the previous content won't be recoverable.
    
    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
    
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
             switch off the mode (command 'c') and change display units to
             sectors (command 'u').
    
    Command (m for help): m
    Command action
       a   toggle a bootable flag
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-652, default 1): 
    Using default value 1
    Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): 326
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    e
    Partition number (1-4): 2
    First cylinder (327-652, default 327): 
    Using default value 327
    Last cylinder, +cylinders or +size{K,M,G} (327-652, default 652): 
    Using default value 652
    
    Command (m for help): m
    Command action
       a   toggle a bootable flag
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@localhost dev]# 
    [root@localhost dev]# fdisk -l 
    
    Disk /dev/sda: 21.5 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00093a1f
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          39      307200   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              39        2358    18631680   83  Linux
    /dev/sda3            2358        2611     2031616   82  Linux swap / Solaris
    
    Disk /dev/sdb: 5368 MB, 5368709120 bytes
    255 heads, 63 sectors/track, 652 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0c4df6a2
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1         326     2618563+  83  Linux
    /dev/sdb2             327         652     2618595    5  Extended
    
    [root@localhost dev]# mkfs.ext3 /dev/sdb1  //格式化分区
    mke2fs 1.41.12 (17-May-2010)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    163840 inodes, 654640 blocks
    32732 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=671088640
    20 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
            32768, 98304, 163840, 229376, 294912
    
    Writing inode tables: done                            
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 25 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    [root@localhost dev]# mkdir /opt/my_disk
    [root@localhost dev]# 
    [root@localhost dev]# mount /dev/sdb1 /opt/my_disk/  //挂载分区
    [root@localhost dev]# cd /opt/my_disk/
    [root@localhost my_disk]# ll
    total 16
    drwx------. 2 root root 16384 Apr 27 10:05 lost+found

    du:检测目录所占磁盘空间,用于统计目录或文件所占磁盘空间的大小,执行结果与df类似,du更侧重于与磁盘的使用状况。

    du -a 递归显示指定目录中各文件和子目录文件占用的数据块;

    du -s 显示指定文件或目录占用的数据块

    du -b 以字节为单位显示磁盘占用情况

    du -l 计算所有文件大小,对硬连接文件计算多次

    [root@localhost home]# cd x 
    [root@localhost x]# ll
    total 104
    -rw-----w-. 1 root root  3361 Apr 15 05:27 anaconda-ks.cfg
    -rw-r--rw-. 1 root root 41915 Apr 15 05:27 install.log
    -rw-r--rw-. 1 root root  9154 Apr 15 05:27 install.log.syslog
    -rw-r--rw-. 1 root root 41915 Apr 15 05:25 my.log
    [root@localhost x]# du -a
    44      ./my.log
    12      ./install.log.syslog
    4       ./anaconda-ks.cfg
    44      ./install.log
    108     .
    [root@localhost x]# du -ab
    41915   ./my.log
    9154    ./install.log.syslog
    3361    ./anaconda-ks.cfg
    41915   ./install.log
    100441  .
    [root@localhost x]# du -s my.log
    44      my.log
    [root@localhost x]# du -al | sort -n
    4       ./anaconda-ks.cfg
    12      ./install.log.syslog
    44      ./install.log
    44      ./my.log
    108     .
    [root@localhost x]# 

     ifconfig:查看网络配置情况,重启网络接口。

    [root@localhost ~]# ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0C:29:6F:58:E8  
              inet addr:192.168.166.128  Bcast:192.168.166.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe6f:58e8/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:1668 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1606 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:154503 (150.8 KiB)  TX bytes:1121694 (1.0 MiB)
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:46 errors:0 dropped:0 overruns:0 frame:0
              TX packets:46 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:2340 (2.2 KiB)  TX bytes:2340 (2.2 KiB)

    [root@localhost ~]# ifconfig eth0 up  //精准方式开启关闭对应接口
    [root@localhost ~]# ifconfig eth0 down
    [root@localhost ~]# service network restart //启动所有网络接口

     ping:测试网络连通性

    [root@localhost ~]# ping -c1 www.baidu.com
    PING www.a.shifen.com (180.97.33.108) 56(84) bytes of data.
    64 bytes from www.baidu.com (180.97.33.108): icmp_seq=1 ttl=128 time=39.4 ms
    
    --- www.a.shifen.com ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 47ms
    rtt min/avg/max/mdev = 39.490/39.490/39.490/0.000 ms

     默认会ping无限次

    [root@localhost ~]# ping  www.baidu.com   
    PING www.a.shifen.com (180.97.33.107) 56(84) bytes of data.
    64 bytes from 180.97.33.107: icmp_seq=1 ttl=128 time=36.9 ms
    64 bytes from 180.97.33.107: icmp_seq=2 ttl=128 time=37.9 ms
    64 bytes from 180.97.33.107: icmp_seq=3 ttl=128 time=36.9 ms
    64 bytes from 180.97.33.107: icmp_seq=4 ttl=128 time=42.4 ms

     tar 解压压缩命令:

    [root@localhost home]# tar -zcvf x.tar.gz x/   //压缩x目录
    x/
    x/my.log
    x/install.log.syslog
    x/anaconda-ks.cfg
    x/install.log
    [root@localhost home]# 
    [root@localhost home]# ll
    total 44
    -rwxrwxrwx.  1 root root    10 Apr 25 11:05 1.txt
    -rwxrwxrwx.  1 zyj  zyj     86 Apr 15 09:23 hello.txt
    drwx------.  4 sl   sl    4096 Apr 25 10:16 sl
    drwxr-xrwx.  2 root root  4096 Apr 15 07:00 x
    -rw-r--r--.  1 root root 21997 Apr 26 10:55 x.tar.gz
    drwx------. 24 zyj  zyj   4096 Apr 26 10:24 zyj
    [root@localhost home]#  
    [root@localhost home]# mv x.tar.gz /opt/
    [root@localhost home]# cd /opt/
    [root@localhost opt]# ll
    total 32
    drwxr-xr-x. 2 root root  4096 Mar 26  2015 rh
    drwxr-xr-x. 2 root root  4096 Apr 15 05:30 x
    -rw-r--r--. 1 root root 21997 Apr 26 10:55 x.tar.gz
    [root@localhost opt]# 
    [root@localhost opt]# 
    [root@localhost opt]# tar -zxvf x.tar.gz //解压缩
    x/
    x/my.log
    x/install.log.syslog
    x/anaconda-ks.cfg
    x/install.log
    [root@localhost opt]# ll
    total 32
    drwxr-xr-x. 2 root root  4096 Mar 26  2015 rh
    drwxr-xrwx. 2 root root  4096 Apr 15 07:00 x
    -rw-r--r--. 1 root root 21997 Apr 26 10:55 x.tar.gz

     netstat 查看网络情况

    [root@localhost ~]# netstat -ntpl
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      2254/sshd           
    tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2095/cupsd          
    tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2392/master         
    tcp        0      0 :::22                       :::*                        LISTEN      2254/sshd           
    tcp        0      0 ::1:631                     :::*                        LISTEN      2095/cupsd          
    tcp        0      0 ::1:25                      :::*                        LISTEN      2392/master 
  • 相关阅读:
    洛谷 P3808 【模板】AC自动机(简单版) 题解
    O3优化模板
    洛谷 P3909 异或之积 题解
    洛谷 P3870 [TJOI2009]开关 题解
    洛谷 P1891 疯狂LCM 题解
    洛谷 P5221 Product 题解
    洛谷 P2568 GCD 题解
    洛谷 P5639 【CSGRound2】守序者的尊严 题解
    扩展kmp板子
    [JZOJ3167] 【GDOI2013模拟3】查税
  • 原文地址:https://www.cnblogs.com/zhaoyujiao/p/8954836.html
Copyright © 2011-2022 走看看