Linux基础知识day-4

基础命令:

  39.top:动态的监控系统的运行装和进程。类似Windows的任务管理器。

top - 23:16:01 up 0 min,  1 user,  load average: 0.06, 0.02, 0.01
Tasks: 236 total,   1 running, 235 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.5 us,  4.7 sy,  0.0 ni, 93.3 id,  0.3 wa,  0.0 hi,  0.2 si,  0.0 st
KiB Mem :  2032156 total,  1629140 free,   187976 used,   215040 buff/cache
KiB Swap:   839676 total,   839676 free,        0 used.  1644708 avail Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  1515 root      20   0  157844   2300   1536 R   5.6  0.1   0:00.04 top
     1 root      20   0  128092   6696   3944 S   0.0  0.3   0:01.61 systemd

第一行:

23:16:01:系统当前时间
up 0 min:系统运行时间
1 user:登陆用户数
load average: 0.06, 0.02, 0.01:系统负载,三个数值分别是1分钟,5分钟,15分钟到现在的平均值

第二行:

Tasks: 236 total[进程总数],   1 running[正在运行], 235 sleeping[睡眠的进程],   0 stopped[停止的进程],   0 zombie[僵尸进程]

第三行:

%Cpu(s):  1.5 us[用户空间占用],  4.7 sy[内核空间占用],  0.0 ni[改变过优先级的进程占用], 93.3 id[空闲cpu百分比],  0.3 wa[等待I/O操作占用],  0.0 hi[硬中断占用],  0.2 si[软中断占用],  0.0 st[被偷走的占用]

第四行和第五行内存信息:

KiB Mem :  2032156 total[总数],  1629140 free[空闲],   187976 used[使用],   215040 buff/cache[用作缓存的总量]
KiB Swap:   839676 total,   839676 free,        0 used.  1644708 avail Mem

buffer和cache指的都是内存中的空间:

    buffer:用于存放要输出到 disk中的数据。

    cache:用于存放 disk 上读出的数据。
    
  程序运行三种状态:
    运行态:CPU正在运行的程序
    就绪态:等待cpu运的程序
    阻塞态:进行其他 I/O操作,不占用CPU,I/O操作完成后返回就绪态

  40.free:用于查看内存的使用状况,还可以显示被内核使用的内存缓冲区。

    -b:显示以字节为单位的输出

    -k:显示以千字节为单位的输出

    -m:以兆字节显示输出

    -g:显示以GB为单位的输出

    -h:以人类可读的方式输出,使用--si参数可以以1024的换算关系显示。

    -w:把buff/cache拆开显示,默认显示buff和cache的总数。

示例:

 1 [root@bogon ~]# free
 2               total        used        free      shared  buff/cache   available
 3 Mem:        2032156      357608     1067776        9408      606772     1459800
 4 Swap:        839676           0      839676
 5 [root@bogon ~]# free -m
 6               total        used        free      shared  buff/cache   available
 7 Mem:           1984         349        1042           9         592        1425
 8 Swap:           819           0         819
 9 [root@bogon ~]# free -h
10               total        used        free      shared  buff/cache   available
11 Mem:           1.9G        349M        1.0G        9.2M        592M        1.4G
12 Swap:          819M          0B        819M
13 [root@bogon ~]# free -h --si
14               total        used        free      shared  buff/cache   available
15 Mem:           2.0G        357M        1.1G        9.4M        606M        1.5G
16 Swap:          839M          0B        839M
17 [root@bogon ~]# free -h --si -w
18               total        used        free      shared     buffers       cache   available
19 Mem:           2.0G        357M        1.1G        9.4M        1.0M        605M        1.5G
20 Swap:          839M          0B        839M
21 [root@bogon ~]# 

  41.mount:用于挂载存储设备到指定的挂载点。

    -a:挂载/etc/mtab中记录的所有文件系统。

    mount [选项] [设备文件名] [挂载点]

1 [root@bogon ~]# mount -v -t iso9660 /dev/sr0 /mnt/iso 
2 mount: /dev/sr0 is write-protected, mounting read-only
3 mount: /dev/sr0 mounted on /mnt/iso.
4 [root@bogon ~]# 

  42.umount:用于卸载挂载点或者挂载设备。

    -a:卸除/etc/mtab中记录的所有文件系统。

    -l:强制卸载

    -R:递归卸载目录及其子对象

1 [root@bogon iso]# pwd
2 /mnt/iso
3 [root@bogon iso]# umount -v /mnt/iso/
4 umount: /mnt/iso: target is busy.
5         (In some cases useful info about processes that use
6          the device is found by lsof(8) or fuser(1))
7 [root@bogon iso]# umount -v -l /mnt/iso/
8 umount: /mnt/iso (/dev/sr0) unmounted
9 [root@bogon iso]# 

  43.df:可以显示目前所有档案系统的最大可用空间及使用状况。

    -h:人类可读的方式输出

    -T:显示文件系统类型

    -i:显示inode 信息而非块使用量

 1 [root@bogon iso]# df
 2 Filesystem          1K-blocks    Used Available Use% Mounted on
 3 /dev/mapper/cl-root   6486016 5125008   1361008  80% /
 4 devtmpfs               999244       0    999244   0% /dev
 5 tmpfs                 1016076     172   1015904   1% /dev/shm
 6 tmpfs                 1016076    9208   1006868   1% /run
 7 tmpfs                 1016076       0   1016076   0% /sys/fs/cgroup
 8 /dev/sda1             1038336  160348    877988  16% /boot
 9 tmpfs                  203216       8    203208   1% /run/user/0
10 tmpfs                  203216      16    203200   1% /run/user/42
11 [root@bogon iso]# df -h
12 Filesystem           Size  Used Avail Use% Mounted on
13 /dev/mapper/cl-root  6.2G  4.9G  1.3G  80% /
14 devtmpfs             976M     0  976M   0% /dev
15 tmpfs                993M  172K  993M   1% /dev/shm
16 tmpfs                993M  9.0M  984M   1% /run
17 tmpfs                993M     0  993M   0% /sys/fs/cgroup
18 /dev/sda1           1014M  157M  858M  16% /boot
19 tmpfs                199M  8.0K  199M   1% /run/user/0
20 tmpfs                199M   16K  199M   1% /run/user/42
21 [root@bogon iso]# df -h -T
22 Filesystem          Type      Size  Used Avail Use% Mounted on
23 /dev/mapper/cl-root xfs       6.2G  4.9G  1.3G  80% /
24 devtmpfs            devtmpfs  976M     0  976M   0% /dev
25 tmpfs               tmpfs     993M  172K  993M   1% /dev/shm
26 tmpfs               tmpfs     993M  9.0M  984M   1% /run
27 tmpfs               tmpfs     993M     0  993M   0% /sys/fs/cgroup
28 /dev/sda1           xfs      1014M  157M  858M  16% /boot
29 tmpfs               tmpfs     199M  8.0K  199M   1% /run/user/0
30 tmpfs               tmpfs     199M   16K  199M   1% /run/user/42
31 [root@bogon iso]# df -h -T -i
32 Filesystem          Type     Inodes IUsed IFree IUse% Mounted on
33 /dev/mapper/cl-root xfs        2.8M  159K  2.6M    6% /
34 devtmpfs            devtmpfs   244K   422  244K    1% /dev
35 tmpfs               tmpfs      249K    12  249K    1% /dev/shm
36 tmpfs               tmpfs      249K   594  248K    1% /run
37 tmpfs               tmpfs      249K    16  249K    1% /sys/fs/cgroup
38 /dev/sda1           xfs        512K   329  512K    1% /boot
39 tmpfs               tmpfs      249K    13  249K    1% /run/user/0
40 tmpfs               tmpfs      249K    17  249K    1% /run/user/42
41 [root@bogon iso]# 

  44.dd:用于复制文件并对原文件的内容进行转换和格式化处理。

    dd测试硬盘速度:dd if=/dev/zero of=/a.txt bs=200M count=1

1 [root@bogon iso]# dd if=/dev/zero of=/a.txt bs=200M count=1
2 1+0 records in
3 1+0 records out
4 209715200 bytes (210 MB) copied, 1.74851 s, 120 MB/s
5 [root@bogon iso]# 

  45.ps:查看系统进程。

    a:显示现行终端机下的所有程序,包括其他用户的程序。

    u:以用户为主的格式来显示程序状况。

    x:显示所有程序,不以终端机来区分。

    e:显示每个程序所使用的环境变量。

    l:采用详细的格式来显示程序状况。

    f:显示程序间的相互关系。

1 [root@bogon iso]# ps aux
2 USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
3 root          1  0.1  0.3 193628  6732 ?        Ss   00:28   0:03 /usr/lib/systemd/systemd --switched-root --system --de
4 root          2  0.0  0.0      0     0 ?        S    00:28   0:00 [kthreadd]
5 root          3  0.0  0.0      0     0 ?        S    00:28   0:00 [ksoftirqd/0]
6 root          5  0.0  0.0      0     0 ?        S<   00:28   0:00 [kworker/0:0H]
7 root          7  0.0  0.0      0     0 ?        S    00:28   0:00 [migration/0]
...
1 [root@bogon iso]# ps elfx
2 F   UID    PID   PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
3 1     0   1400   1398  20   0  15516   180 pipe_w S    ?          0:00 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmas
4 1     0      2      0  20   0      0     0 kthrea S    ?          0:00 [kthreadd]
5 1     0      3      2  20   0      0     0 smpboo S    ?          0:00  \_ [ksoftirqd/0]
6 1     0      5      2   0 -20      0     0 worker S<   ?          0:00  \_ [kworker/0:0H]
7 1     0      7      2 -100  -      0     0 smpboo S    ?          0:00  \_ [migration/0]
8 1     0      8      2  20   0      0     0 rcu_gp S    ?          0:00  \_ [rcu_bh]
...

  46.pstree:显示进程树

  47.“&”命令后加入“&”符号表示后台运行。

  48.kill:杀死一个进程。kill [pid]

  49.pkill:也是杀死一个进程。pkill [进程名字]

1 [root@bogon ~]# firefox &
2 [1] 4332
3 [root@bogon ~]# kill 4332
4 [root@bogon ~]# firefox &
5 [2] 4433
6 [1]   Terminated              firefox
7 [root@bogon ~]# pkill firefox
8 [root@bogon ~]# 

  50.fdisk:磁盘分区命令。

    -l:显示当前系统的磁盘分区

      - 使用方式:使用fdisk [设备名],开始对设备进行操作。

      - 进入分区模式的时候,按m键来获取相关帮助

      - 按n来新建分区,选择一个分区类型,p创建主分区,e创建扩展分区

      - 输入分区号、输入其实位置,一般默认就好、输入分区大小

      - 按p打印分区信息

      - 按w保存分区

例如:在/dev/sdb磁盘上创建一个主分区,大小1G。

 1 [root@bogon ~]# fdisk /dev/sdb
 2 Welcome to fdisk (util-linux 2.23.2).
 3 
 4 Changes will remain in memory only, until you decide to write them.
 5 Be careful before using the write command.
 6 
 7 Device does not contain a recognized partition table
 8 Building a new DOS disklabel with disk identifier 0x36e14b60.
 9 
10 Command (m for help): m  
11 Command action
12    a   toggle a bootable flag
13    b   edit bsd disklabel
14    c   toggle the dos compatibility flag
15    d   delete a partition
16    g   create a new empty GPT partition table
17    G   create an IRIX (SGI) partition table
18    l   list known partition types
19    m   print this menu
20    n   add a new partition
21    o   create a new empty DOS partition table
22    p   print the partition table
23    q   quit without saving changes
24    s   create a new empty Sun disklabel
25    t   change a partition's system id
26    u   change display/entry units
27    v   verify the partition table
28    w   write table to disk and exit
29    x   extra functionality (experts only)
30 
31 Command (m for help): n
32 Partition type:
33    p   primary (0 primary, 0 extended, 4 free)
34    e   extended
35 Select (default p): p
36 Partition number (1-4, default 1): 
37 First sector (2048-4194303, default 2048): 
38 Using default value 2048
39 Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): +1G  
40 Partition 1 of type Linux and of size 1 GiB is set
41 
42 Command (m for help): p
43 
44 Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
45 Units = sectors of 1 * 512 = 512 bytes
46 Sector size (logical/physical): 512 bytes / 512 bytes
47 I/O size (minimum/optimal): 512 bytes / 512 bytes
48 Disk label type: dos
49 Disk identifier: 0x36e14b60
50 
51    Device Boot      Start         End      Blocks   Id  System
52 /dev/sdb1            2048     2099199     1048576   83  Linux
53 
54 Command (m for help): w
55 The partition table has been altered!
56 
57 Calling ioctl() to re-read partition table.
58 Syncing disks.
59 [root@bogon ~]# 

 

posted @ 2017-05-26 17:38  neuropathy_ldsly  阅读(182)  评论(0)    收藏  举报