Linux 进程管理(1)

279 阅读4分钟

这是我参与更文挑战的第21天 ,活动详情查看更文挑战

磁盘管理

df

磁盘空间使用情况 df [选项]

  • a : 显示所有文件系统的磁盘使用情况
  • h : 以友好直观方式显示信息,即以KB或MB为单位
  • T : 显示文件系统类型

[root@localhost ~]# df /home   #指定一个文件夹,查看该文件夹所在磁盘的使用情况
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             16036224   2749160  12459316  19% /
 
[root@localhost ~]# df /bin/ls   #指定一个文件
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             16036224   2749160  12459316  19% /
 
[root@localhost ~]# df /bin/ls /home  #指定多个文件或文件夹
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             16036224   2749160  12459316  19% /
/dev/sda2             16036224   2749160  12459316  19% /
 
[root@localhost ~]# df /bin/ls /home /usr/  #指定多个文件或文件夹
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             16036224   2749160  12459316  19% /
/dev/sda2             16036224   2749160  12459316  19% /
/dev/sda2             16036224   2749160  12459316  19% /
 
[root@localhost ~]# df   # 默认情况
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             16036224   2750464  12458012  19% /
/dev/sda1               295561     16911    263390   7% /boot
tmpfs                  1028272         0   1028272   0% /dev/shm

例子:以友好直观方式显示所有文件系统的使用情况,并列出文件系统类型

df -ahT

du

统计目录或文件所占磁盘空间大小 du [选项/参数] [目录名…]

  • a : 递归显示制定目录中各个文件及下级目录中各文件占用的数据块数
  • h : 以友好直观方式显示信息,即以KB或MB为单位
  • b : 以字节为单位列出磁盘空间使用情况
  • k : 以KB为单位显示
  • s : 对每个目录参数只给出占用的数据块总数
[maple@linux ~]$

[maple@linux ~]$ du

8       ./test/links

8       ./test/dir/subdir1

8       ./test/dir/subdir2

20      ./test/dir

160     ./test

108     ./test2

1492    .

[maple@linux ~]$

[maple@linux ~]$ du -0

8       ./test/links8   ./test/dir/subdir18     ./test/dir/subdir220    ./test/dir160   ./test108       ./test21492  .[maple@linux ~]$ du -c

8       ./test/links

8       ./test/dir/subdir1

8       ./test/dir/subdir2

20      ./test/dir

160     ./test

108     ./test2

1492    .

1492    total

[maple@linux ~]$

[maple@linux ~]$ du -h

8.0K    ./test/links

8.0K    ./test/dir/subdir1

8.0K    ./test/dir/subdir2

20K     ./test/dir

160K    ./test

108K    ./test2

1.5M    .

[maple@linux ~]$

[maple@linux ~]$ du -k

8       ./test/links

8       ./test/dir/subdir1

8       ./test/dir/subdir2

20      ./test/dir

160     ./test

108     ./test2

1492    .

[maple@linux ~]$

[maple@linux ~]$ du -sh

1.5M    .

[maple@linux ~]$

[maple@linux ~]$ du -S

8       ./test/links

8       ./test/dir/subdir1

8       ./test/dir/subdir2

4       ./test/dir

132     ./test

108     ./test2

1224    .

[maple@linux ~]$

[maple@linux ~]$ du -Sh --exclude="sub*"

8.0K    ./test/links

4.0K    ./test/dir

132K    ./test

108K    ./test2

1.2M    .

[maple@linux ~]$

[maple@linux ~]$ du -h

8.0K    ./test/links

8.0K    ./test/dir/subdir1

8.0K    ./test/dir/subdir2

20K     ./test/dir

160K    ./test

108K    ./test2

1.5M    .

[maple@linux ~]$

例子:以KB为单位,显示/tmp目录占用的磁盘空间情况

du -k /tmp

账号管理和查看命令

  • whoami命令的功能在于显示用户自身的用户名。
  • who [选项]:该命令主要用于查看当前在线的用户情况 -H:显示时加上头标志
  • w命令 :用于显示登录到系统的用户情况,是who的增强版 w | more
  • id [选项] : 显示用户信息 -g:显示工作组信息 -u:显示用户信息
  • finger命令:可用于查找和显示用户信息,并且在查找后显示指定账号的相关信息
  • chfn命令:能够改变系统存储的用户信息
  • 切换用户身份:su [用户名]

进程的概念

Linux操作系统包括三种不同类型的进程,每种进程都有自己的特点和属性:

  • 交互进程:由shell启动的进程。
  • 批处理进程:这种进程和终端没有联系,是一个进程序列。
  • 守护进程:在后台持续运行的进程。

启动进程/手工启动

  • 前台启动:一般地,用户键入一个命令,就已经启动了一个前台的进程。 中断前台进程 ctrl+c/ kill
  • 后台启动:对于非常耗时进程,可以让进程在后台运行。从后台启动进程其实就是在命令结尾加上一个“&”号,例:updaedb &
  1. jobs 显示所有后台进程
  2. ctrl+z 前台->后台,并暂停
  3. fg 将后台进程调到前台执行
  4. bg 将一个后台暂停的进程,继续执行