swap交换分区及buffers和cached

swap交换分区

swap 是 linux 系统磁盘管理的一块特殊的分区,当实际的物理内存不足的时候,操作系统会从整个内存中,取出一部分暂时没在使用的内存,拿出来放到交换分区,从而提供给当前正在使用的程序,可以使用更多的内存。
使用 swap 分区的作用是,通过操作系统的调取,程序可以用到的实际内存,会远大于物理内存。
swap 分区大小,必须根据物理内存和硬盘容量来计算
-当你的物理内存小于 1G,必须使用 swap 提升内存使用量
-内存使用过多的应用程序,比如图像,视频等,必须用 swap 分区防止物理内存不足,造成软件崩溃。
-当你的电脑休眠,内存中的数据会放入 swap 交换分区中,当你的电脑恢复后,再从 swap 中读取数据,恢复软件正常工作

创建 swap 分区
centos7 系统,计算 swap 分区如下:
-内存小于2G, swap 分配和内存同样大小的空间
-内存大于2G, swap 也就分配2G空间

1.先给磁盘分一个区,得指定 swap 分区类型, fdisk /dev/sdc
2.针对磁盘分区进行格式化 mkswap /dev/sdc1
3.再来使用 swap 分区 swapon 开启交换空间 swapoff 关闭交换空间

swap 代码验证

root@ubuntu:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3870         660        2636          13         573        2968
Swap:           2047           0        2047

root@ubuntu:~# fdisk -l | grep sdc
Disk /dev/sdc: 120 GiB, 128849018880 bytes, 251658240 sectors
/dev/sdc1      34   976562   976529 476.8M Linux filesystem
/dev/sdc2  978944 97656831 96677888  46.1G Linux filesystem

第一种 GPT格式 磁盘分区 创建 swap 交换分区
# 进入创建分区磁盘
root@ubuntu:~# parted /dev/sdc
GNU Parted 3.4
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p    # 打印磁盘分区信息                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  500MB   500MB   ext4         primary
 2      501MB   50.0GB  49.5GB  ntfs         logical

# 创建主分区
(parted) mkpart primary 50001 52000                                       
(parted) p   # 打印分区信息                                                             
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  500MB   500MB   ext4         primary
 2      501MB   50.0GB  49.5GB  ntfs         logical
 3      50.0GB  52.0GB  1999MB               primary

# 创建 swap 交换分区
(parted) t                                                                
Partition number? 3                                                       
Flag to Invert? swap                                                      
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  500MB   500MB   ext4         primary
 2      501MB   50.0GB  49.5GB  ntfs         logical
 3      50.0GB  52.0GB  1999MB               primary  swap

(parted) q     # 退出                                                           
Information: You may need to update /etc/fstab.


root@ubuntu:~# fdisk -l | grep sdc
Disk /dev/sdc: 120 GiB, 128849018880 bytes, 251658240 sectors
/dev/sdc1        34    976562   976529 476.8M Linux filesystem
/dev/sdc2    978944  97656831 96677888  46.1G Linux filesystem
/dev/sdc3  97658880 101562367  3903488   1.9G Linux swap
root@ubuntu:~# parted /dev/sdc
GNU Parted 3.4
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  500MB   500MB   ext4         primary
 2      501MB   50.0GB  49.5GB  ntfs         logical
 3      50.0GB  52.0GB  1999MB               primary  swap

(parted) q   
# 对 /dev/sdc3 分区进行 swap 格式化
root@ubuntu:~# mkswap /dev/sdc3
Setting up swapspace version 1, size = 1.9 GiB (1998581760 bytes)
no label, UUID=6afd7ed9-2ff8-4306-8721-9030287a5609
# 查看磁盘分区信息
root@ubuntu:~# parted /dev/sdc
GNU Parted 3.4
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name     Flags
 1      17.4kB  500MB   500MB   ext4            primary
 2      501MB   50.0GB  49.5GB  ntfs            logical
 3      50.0GB  52.0GB  1999MB  linux-swap(v1)  primary  swap
 root@ubuntu:~# fdisk -l | grep sdc
Disk /dev/sdc: 120 GiB, 128849018880 bytes, 251658240 sectors
/dev/sdc1        34    976562   976529 476.8M Linux filesystem
/dev/sdc2    978944  97656831 96677888  46.1G Linux filesystem
/dev/sdc3  97658880 101562367  3903488   1.9G Linux swap



第二中  MBR格式 磁盘分区  创建 swap 交换分区
root@ubuntu:~# fdisk -l | grep sd
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
/dev/sda1     2048      4095      2048    1M BIOS boot
/dev/sda2     4096   1054719   1050624  513M EFI System
/dev/sda3  1054720 209713151 208658432 99.5G Linux filesystem
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk /dev/sdc: 120 GiB, 128849018880 bytes, 251658240 sectors
/dev/sdc1        34    976562   976529 476.8M Linux filesystem
/dev/sdc2    978944  97656831 96677888  46.1G Linux filesystem
/dev/sdc3  97658880 101562367  3903488   1.9G Linux swap
root@ubuntu:~# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf4813d41

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-209715199, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715199, default 209715199): +500M

Created a new partition 1 of type 'Linux' and of size 500 MiB.

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): t
Selected partition 1
Hex code or alias (type L to list all): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Command (m for help): p
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf4813d41

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1        2048 1026047 1024000  500M 82 Linux swap / Solaris

# 把创建的 swap 交换分区写入磁盘
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@ubuntu:~# fdisk -l | grep sdb
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
/dev/sdb1        2048 1026047 1024000  500M 82 Linux swap / Solaris

root@ubuntu:~# lsblk -f | grep sdb
sdb                                                                                                     
└─sdb1   
# 对 /dev/sdb1 分区进行 swap 格式化
root@ubuntu:~# mkswap /dev/sdb1
Setting up swapspace version 1, size = 500 MiB (524283904 bytes)
no label, UUID=e353971b-a7cf-488d-9b1c-db22e2958411
root@ubuntu:~# lsblk -f | grep sdb
sdb                                                                                                     
└─sdb1 swap     1                                   e353971b-a7cf-488d-9b1c-db22e2958411 

root@ubuntu:~# fdisk -l | grep sd
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
/dev/sda1     2048      4095      2048    1M BIOS boot
/dev/sda2     4096   1054719   1050624  513M EFI System
/dev/sda3  1054720 209713151 208658432 99.5G Linux filesystem
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
/dev/sdb1        2048 1026047 1024000  500M 82 Linux swap / Solaris
Disk /dev/sdc: 120 GiB, 128849018880 bytes, 251658240 sectors
/dev/sdc1        34    976562   976529 476.8M Linux filesystem
/dev/sdc2    978944  97656831 96677888  46.1G Linux filesystem
/dev/sdc3  97658880 101562367  3903488   1.9G Linux swap



# 如何使用 swap 交换分区
root@ubuntu:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3870         592        2687          13         591        3036
Swap:           2047           0        2047

root@ubuntu:~# sw
swaplabel      swapoff        swapon         switcherooctl  switch_root  

# 开启 /dev/sdb1 设备的 swap 交换分区	 swapon /dev/sdb1
root@ubuntu:~# swapon /dev/sdb1
root@ubuntu:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3870         588        2690          13         591        3040
Swap:           2547           0        2547

# 开启 /dev/sdc3 设备的 swap 交换分区	swapon /dev/sdc3
root@ubuntu:~# swapon /dev/sdc3
root@ubuntu:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3870         591        2687          13         591        3036
Swap:           4453           0        4453

#  关闭  /dev/sdb1 设备的 swap 交换分区  swapoff /dev/sdb1
# 关闭 /dev/sdc3 设备的 swap 交换分区	swapoff /dev/sdc3

root@ubuntu:~# swapoff /dev/sdb1
root@ubuntu:~# swapoff /dev/sdc3
root@ubuntu:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3870         594        2684          13         591        3034
Swap:           2047           0        2047

buffers 和 cached解析

buffers 缓冲区 buffers 是给写入数据加速使用的
cached 缓存 cached 是用于读取数据时,加速使用的。
cached 表示把数据从磁盘上读取出来,保存在内存中,再次读取的时候,不再去硬盘上拉取数据,直接从内存中读取,加速查找。
buffers 表示在写入磁盘数据的时候,把分散的操作临时保存到内存中,达到一定的数量之后,集中写入到磁盘,减少磁盘碎片,加速数据查找,减少磁头的反复的寻道时间。

buff 和 cache 的作用总结

-buffers 和 cached 都是基于内存的存储中间层
cached 解决的时间问题,加速读取的过程
buffers 解决空间存储问题,给数据一个临时存放的区域。
cached 利用内存的高速读写特性,
buffers 利用了内存的存储空间特性。

#########

我的内存被吃了,无辜提示内存不足了怎么办,但是在 cache,buff 中又看到大量的内存,如何释放
解决方案:
1. 释放cache 的命令
echo 1 > /proc/sys/vm/drop_caches 也可以用 sysctl -w vm.drop_caches=1 命令
命令解释:
"echo 1" 是释放 buff 的一个命令参数,把 "1"写入到 /proc/sys/vm/drop_caches 文件中, "1" 代表为真,让删除缓存生效。
2.清除目录缓存和 inodes 命令
echo 2 > /proc/sys/vm/drop_caches 也可以用 sysctl -w vm.drop_caches=2 命令
3. 清除内存页的缓存
echo 3 > /proc/sys/vm/drop_caches 也可以用 sysctl -w vm.drop_caches=3 命令
以上三种方式都是临时释放缓存的命令,
要永久生效 vim /etc/sysctl.conf 将要清除的命令写入到这个文件中
除了以上3个命令,还可以清理文件系统缓存,使用 sync 命令,可以用于清理僵尸进程(就是主进程挂了,剩下的子进程就群龙无首,变僵尸进程了)
sync 的作用:将内存缓冲区的数据,写入到磁盘中

实战

root@ubuntu:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3870         599        2252          13        1019        3022
Swap:           2047           0        2047
root@ubuntu:~# echo 1 > /proc/sys/vm/drop_caches  # 1 代表 cache
root@ubuntu:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3870         595        2985          13         289        3028
Swap:           2047           0        2047

#  同步sync 将内存中缓冲区的数据写入到磁盘中
root@ubuntu:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3870         587        2978          13         303        3036
Swap:           2047           0        2047
root@ubuntu:~# sync
root@ubuntu:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3870         590        2975          13         303        3033
Swap:           2047           0        2047

root@ubuntu:~# swapon /dev/sdc3
root@ubuntu:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3870         591        2974          13         304        3032
Swap:           3953           0        3953
root@ubuntu:~# swapoff /dev/sdc3
root@ubuntu:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3870         591        2974          13         304        3033
Swap:           2047           0        2047
root@ubuntu:~# vim /etc/sysctl.conf
root@ubuntu:~# cat /etc/sysctl.conf
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additional system variables.
# See sysctl.conf (5) for information.
#

#kernel.domainname = example.com

# Uncomment the following to stop low-level messages on console
#kernel.printk = 3 4 1 3

###################################################################
# Functions previously found in netbase
#

# Uncomment the next two lines to enable Spoof protection (reverse-path filter)
# Turn on Source Address Verification in all interfaces to
# prevent some spoofing attacks
#net.ipv4.conf.default.rp_filter=1
#net.ipv4.conf.all.rp_filter=1

# Uncomment the next line to enable TCP/IP SYN cookies
# See http://lwn.net/Articles/277146/
# Note: This may impact IPv6 TCP sessions too
#net.ipv4.tcp_syncookies=1

# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1

# Uncomment the next line to enable packet forwarding for IPv6
#  Enabling this option disables Stateless Address Autoconfiguration
#  based on Router Advertisements for this host
#net.ipv6.conf.all.forwarding=1


###################################################################
# Additional settings - these settings can improve the network
# security of the host and prevent against some network attacks
# including spoofing attacks and man in the middle attacks through
# redirection. Some network environments, however, require that these
# settings are disabled so review and enable them as needed.
#
# Do not accept ICMP redirects (prevent MITM attacks)
#net.ipv4.conf.all.accept_redirects = 0
#net.ipv6.conf.all.accept_redirects = 0
# _or_
# Accept ICMP redirects only for gateways listed in our default
# gateway list (enabled by default)
# net.ipv4.conf.all.secure_redirects = 1
#
# Do not send ICMP redirects (we are not a router)
#net.ipv4.conf.all.send_redirects = 0
#
# Do not accept IP source route packets (we are not a router)
#net.ipv4.conf.all.accept_source_route = 0
#net.ipv6.conf.all.accept_source_route = 0
#
# Log Martian Packets
#net.ipv4.conf.all.log_martians = 1
#

###################################################################
# Magic system request Key
# 0=disable, 1=enable all, >1 bitmask of sysrq functions
# See https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html
# for what other values do
#kernel.sysrq=438

开机自动挂载与磁盘容量统计

#######

开机自动挂载文件

1.由于 mount 命令直接输入是临时生效,下次重启,挂载的设备分区就无法使用了,因此就出现了一个 /etc/fstab 文件,存放系统一些静态文件的地方,主要是系统启动的时候,系统默认的读取这个文件的信息,将指定的挂载点,进行挂载。
# 通过 mount -a 命令,可以读取 /etc/fstab 文件所有的挂载情况
/dev/sdc2 /mnt ntfs defaults 0 0

解析如上的参数:

第一列:"/dev/sdc2" 是设备的名字,可以是文件系统,也可以是设备名称,NFS 远程网络文件系统。
mount /dev/sdc2 /mnt # 第一种写法
mount 192.168.11.15:/home/ntfs /mnt/ -o nolock
# 把本地的 /mnt 文件夹挂载到 ntfs 文件系统上,且不加锁
第二列:挂载点
就是自己创建的一个目录,是一个已经存在的目录
第三列:linux系统能够支持的文件系统类型
ext3 ext4 nfs swap ntfs xfs
第四列:挂载的功能选项,有很多,默认使用 defaults
第五列:dump
表示将整个文件夹内容备份,一般不对挂载点备份,默认都是0,
第六列:fsck 磁盘检查
默认都是0,不对磁盘进行检查,但是根文件系统,默认是检查的,vim /etc/fstab 在最后添加一行
/dev/sdb5 /mnt xfs defaults 0 0 (centos7)

=======

df 命令,检查挂载点的使用情况
df 命令的实际案例
可使用的命令参数
-h 显示 kb mb单位大小
-i 显示 inode 数量

========

du 命令,显示磁盘空间大小的命令,文件大小的命令
linux 文件存储最小单位是 4k,也就是8个扇区
du -h 显示文件大小 kb mb 为显示单位
du -h * 显示当前目录所有文件的大小
du -a 显示目录中所有文件的大小
du -ah * 显示所有文件的大小信息
统计 /opt/目录下第1层目录大小
du -ah --max-depth=1 /opt/ # '--max-depth=1' 就是指定文件夹深度的参数
显示出当前目录下所有文件,除了 .conf文件的大小 参数作用是,指定排除文件名的作用
du -ah --exclude='*.conf' /opt/

实战

# 在该文件(/etc/fstab)最后一行添加如下一行 就表示永久挂载 /dev/sdc2 这个设备了
root@ubuntu:~# vim /etc/fstab   
root@ubuntu:~# tail -1 /etc/fstab
/dev/sdc2       /mnt    ntfs    defaults                        0               0


root@ubuntu:~# vim /etc/fstab
root@ubuntu:~# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda3 during installation
UUID=f4b2aa80-fa0b-417e-ab7b-fa27caf2f921 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda2 during installation
UUID=4D72-6786  /boot/efi       vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0

# 目录挂载以后,源目录的内容将被隐藏
root@ubuntu:~# touch /mnt/超哥带你学linux.txt
root@ubuntu:~# ls /mnt/
超哥带你学linux.txt

# 挂载以后,挂载目录将显示 /dev/sdc2 设备上的内容
root@ubuntu:~# mount /dev/sdc2 /mnt
root@ubuntu:~# ls /mnt/
test.txt

root@ubuntu:~# umount /mnt
root@ubuntu:~# ls /mnt/
超哥带你学linux.txt

# 已经挂载文件的使用情况
root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           388M  1.9M  386M   1% /run
/dev/sda3        98G   11G   83G  12% /
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/sda2       512M  6.1M  506M   2% /boot/efi
tmpfs           388M   72K  387M   1% /run/user/126
tmpfs           388M   56K  387M   1% /run/user/0
/dev/sdc2        47G   66M   47G   1% /mnt

# 已经挂载文件的使用情况 再加一个大写的T参数,可以显示文件系统类型
root@ubuntu:~# df -hT
Filesystem     Type     Size  Used Avail Use% Mounted on
tmpfs          tmpfs    388M  1.9M  386M   1% /run
/dev/sda3      ext4      98G   11G   83G  12% /
tmpfs          tmpfs    1.9G     0  1.9G   0% /dev/shm
tmpfs          tmpfs    5.0M  4.0K  5.0M   1% /run/lock
/dev/sda2      vfat     512M  6.1M  506M   2% /boot/efi
tmpfs          tmpfs    388M   72K  387M   1% /run/user/126
tmpfs          tmpfs    388M   56K  387M   1% /run/user/0
/dev/sdc2      fuseblk   47G   66M   47G   1% /mnt

# -i 参数 显示 inode 数量
root@ubuntu:~# df -i
Filesystem       Inodes  IUsed    IFree IUse% Mounted on
tmpfs            495434   1134   494300    1% /run
/dev/sda3       6520832 202164  6318668    4% /
tmpfs            495434      1   495433    1% /dev/shm
tmpfs            495434      4   495430    1% /run/lock
/dev/sda2             0      0        0     - /boot/efi
tmpfs             99086     83    99003    1% /run/user/126
tmpfs             99086     54    99032    1% /run/user/0
/dev/sdc2      48304176     20 48304156    1% /mnt

root@ubuntu:~# df -i -h
Filesystem     Inodes IUsed IFree IUse% Mounted on
tmpfs            484K  1.2K  483K    1% /run
/dev/sda3        6.3M  198K  6.1M    4% /
tmpfs            484K     1  484K    1% /dev/shm
tmpfs            484K     4  484K    1% /run/lock
/dev/sda2           0     0     0     - /boot/efi
tmpfs             97K    83   97K    1% /run/user/126
tmpfs             97K    54   97K    1% /run/user/0
/dev/sdc2         47M    20   47M    1% /mnt

# 显示当前目录指定文件名的大小 
root@ubuntu:/tmp# du -h hehe.txt
4.0K    hehe.txt
root@ubuntu:/tmp# du -h /opt/*
4.0K    /opt/akdxfhfnejeikjaaksdklf
0       /opt/aklf
4.0K    /opt/happy2
# 显示所有文件的大小信息
root@ubuntu:/tmp# du -ah /etc/*   所有文件大小都能被4整除
4.0K    /etc/acpi/asus-keyboard-backlight.sh
4.0K    /etc/acpi/asus-wireless.sh
4.0K    /etc/acpi/events/lenovo-undock
4.0K    /etc/acpi/events/asus-wireless-off
4.0K    /etc/acpi/events/asus-keyboard-backlight-down
4.0K    /etc/acpi/events/asus-keyboard-backlight-up
4.0K    /etc/acpi/events/thinkpad-cmos
4.0K    /etc/acpi/events/ibm-wireless
4.0K    /etc/acpi/events/asus-wireless-on
4.0K    /etc/acpi/events/tosh-wireless
36K     /etc/acpi/events
4.0K    /etc/acpi/ibm-wireless.sh
4.0K    /etc/acpi/tosh-wireless.sh

# 统计 /opt/目录下第1层目录大小
root@ubuntu:/tmp# du  -ah  --max-depth=1  /opt/
0       /opt/aklf
4.0K    /opt/happy2
4.0K    /opt/akdxfhfnejeikjaaksdklf
12K     /opt/

# 统计 /opt/目录下第2层目录大小
root@ubuntu:/tmp# du  -ah  --max-depth=2  /opt/
0       /opt/aklf
4.0K    /opt/happy2
0       /opt/akdxfhfnejeikjaaksdklf/我是超哥
4.0K    /opt/akdxfhfnejeikjaaksdklf
12K     /opt/

# 显示出当前目录下所有文件,除了 .conf文件的大小 参数作用是,指定排除文件名的作用
root@ubuntu:/tmp# du  -ah  --exclude='*.conf'  /opt/
0       /opt/aklf
4.0K    /opt/happy2
0       /opt/akdxfhfnejeikjaaksdklf/我是超哥
4.0K    /opt/akdxfhfnejeikjaaksdklf
12K     /opt/



root@ubuntu:~# mount -l
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=1943452k,nr_inodes=485863,mode=755,inode64)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=396348k,mode=755,inode64)
/dev/sda3 on / type ext4 (rw,relatime,errors=remount-ro)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k,inode64)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=30431)
tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)
configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)
ramfs on /run/credentials/systemd-sysusers.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700)
/var/lib/snapd/snaps/bare_5.snap on /snap/bare/5 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core_16574.snap on /snap/core/16574 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core_16202.snap on /snap/core/16202 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core20_2105.snap on /snap/core20/2105 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core20_2182.snap on /snap/core20/2182 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core22_1033.snap on /snap/core22/1033 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/firefox_631.snap on /snap/firefox/631 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/firefox_3779.snap on /snap/firefox/3779 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/snap-store_959.snap on /snap/snap-store/959 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/gnome-42-2204_141.snap on /snap/gnome-42-2204/141 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/snap-store_557.snap on /snap/snap-store/557 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core22_1122.snap on /snap/core22/1122 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/gtk-common-themes_1535.snap on /snap/gtk-common-themes/1535 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/gnome-3-38-2004_143.snap on /snap/gnome-3-38-2004/143 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/dev/sda3 on /var/snap/firefox/common/host-hunspell type ext4 (ro,noexec,noatime,errors=remount-ro)
/var/lib/snapd/snaps/gtk-common-themes_1519.snap on /snap/gtk-common-themes/1519 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/gnome-3-38-2004_76.snap on /snap/gnome-3-38-2004/76 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/dev/sda2 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,nosuid,nodev,noexec,relatime)
tmpfs on /run/user/126 type tmpfs (rw,nosuid,nodev,relatime,size=396344k,nr_inodes=99086,mode=700,uid=126,gid=132,inode64)
gvfsd-fuse on /run/user/126/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=126,group_id=132)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=396344k,nr_inodes=99086,mode=700,inode64)
root@ubuntu:~# lsblk -f | grep sd
sda                                                                                                     
├─sda1                                                                                                  
├─sda2 vfat     FAT32                               4D72-6786                             505.9M     1% /boot/efi
└─sda3 ext4     1.0                                 f4b2aa80-fa0b-417e-ab7b-fa27caf2f921   82.2G    11% /var/snap/firefox/common/host-hunspell
sdb                                                                                                     
└─sdb1 swap     1                                   e353971b-a7cf-488d-9b1c-db22e2958411                
sdc                                                                                                     
├─sdc1 ext4     1.0                                 52572ca0-5fbf-4604-b1df-e887a0af43dd                
├─sdc2 ntfs                                         0B145F533BB37153                                    
└─sdc3 swap     1                                   6afd7ed9-2ff8-4306-8721-9030287a5609  root@ubuntu:~# mount /dev/sdc2 /mnt
root@ubuntu:~# lsblk -f | grep sd
sda                                                                                                     
├─sda1                                                                                                  
├─sda2 vfat     FAT32                               4D72-6786                             505.9M     1% /boot/efi
└─sda3 ext4     1.0                                 f4b2aa80-fa0b-417e-ab7b-fa27caf2f921   82.2G    11% /var/snap/firefox/common/host-hunspell
sdb                                                                                                     
└─sdb1 swap     1                                   e353971b-a7cf-488d-9b1c-db22e2958411                
sdc                                                                                                     
├─sdc1 ext4     1.0                                 52572ca0-5fbf-4604-b1df-e887a0af43dd                
├─sdc2 ntfs                                         0B145F533BB37153                         46G     0% /mnt
└─sdc3 swap     1                                   6afd7ed9-2ff8-4306-8721-9030287a5609 

root@ubuntu:~# mount -l
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=1943452k,nr_inodes=485863,mode=755,inode64)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=396348k,mode=755,inode64)
/dev/sda3 on / type ext4 (rw,relatime,errors=remount-ro)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k,inode64)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=30431)
tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)
configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)
ramfs on /run/credentials/systemd-sysusers.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700)
/var/lib/snapd/snaps/bare_5.snap on /snap/bare/5 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core_16574.snap on /snap/core/16574 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core_16202.snap on /snap/core/16202 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core20_2105.snap on /snap/core20/2105 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core20_2182.snap on /snap/core20/2182 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core22_1033.snap on /snap/core22/1033 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/firefox_631.snap on /snap/firefox/631 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/firefox_3779.snap on /snap/firefox/3779 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/snap-store_959.snap on /snap/snap-store/959 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/gnome-42-2204_141.snap on /snap/gnome-42-2204/141 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/snap-store_557.snap on /snap/snap-store/557 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/core22_1122.snap on /snap/core22/1122 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/gtk-common-themes_1535.snap on /snap/gtk-common-themes/1535 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/gnome-3-38-2004_143.snap on /snap/gnome-3-38-2004/143 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/dev/sda3 on /var/snap/firefox/common/host-hunspell type ext4 (ro,noexec,noatime,errors=remount-ro)
/var/lib/snapd/snaps/gtk-common-themes_1519.snap on /snap/gtk-common-themes/1519 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/gnome-3-38-2004_76.snap on /snap/gnome-3-38-2004/76 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/dev/sda2 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,nosuid,nodev,noexec,relatime)
tmpfs on /run/user/126 type tmpfs (rw,nosuid,nodev,relatime,size=396344k,nr_inodes=99086,mode=700,uid=126,gid=132,inode64)
gvfsd-fuse on /run/user/126/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=126,group_id=132)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=396344k,nr_inodes=99086,mode=700,inode64)
/dev/sdc2 on /mnt type fuseblk (rw,relatime,user_id=0,group_id=0,allow_other,blksize=4096)	# 可以看到 /dev/sdc2 挂载的内容

 

 

 

 

  • 9
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值