linux磁盘命令详解

转自:https://www.cnblogs.com/jxhd1/p/6700300.html

https://www.cnblogs.com/lsgxeva/p/9610003.html

https://www.cnblogs.com/DswCnblog/p/5860166.html

一:df命令

df 命令:

linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息。

1.命令格式:

df [选项] [文件]

2.命令功能:

显示指定磁盘文件的可用空间。如果没有文件名被指定,则所有当前被挂载的文件系统的可用空间将被显示。默认情况下,磁盘空间将以 1KB 为单位进行显示,除非环境变量 POSIXLY_CORRECT 被指定,那样将以512字节为单位进行显示。

3.命令参数:

必要参数:

-a 全部文件系统列表

-h 方便阅读方式显示

-H 等于“-h”,但是计算式,1K=1000,而不是1K=1024

-i 显示inode信息

-k 区块为1024字节

-l 只显示本地文件系统

-m 区块为1048576字节

--no-sync 忽略 sync 命令

-P 输出格式为POSIX

--sync 在取得磁盘信息前,先执行sync命令

-T 文件系统类型

选择参数:

--block-size=<区块大小> 指定区块大小

-t<文件系统类型> 只显示选定文件系统的磁盘信息

-x<文件系统类型> 不显示选定文件系统的磁盘信息

--help 显示帮助信息

--version 显示版本信息

“df -h”这条命令再熟悉不过。以更易读的方式显示目前磁盘空间和使用情况。

“df -i” 以inode模式来显示磁盘使用情况。

df -h 和df -i的区别是什么?同样是显示磁盘使用情况,为什么显示占用百分比相差甚远?

df -h的比较好解释,就是查看磁盘容量的使用情况。

至于df -i,先需要去理解一下inode
以博客主的个人理解,最简单的说法,inode包含的信息:文件的字节数,拥有者id,组id,权限,改动时间,链接数,数据block的位置。相反是不表示文件大小。这就是为什么df -h和df -i 显示的结果是不一样的原因。

ps:在df -h 和df -i  显示使用率100%,基本解决方法都是删除文件。

df -h   是去删除比较大无用的文件-----------大文件占用大量的磁盘容量。

df -i    则去删除数量过多的小文件-----------过多的文件占用了大量的inode号。

二:fdisk命令

fdisk 命令可以查看磁盘的一些情况和对磁盘进行分区操作。

fdisk -l 查看磁盘信息。

$ fdisk -l
/dev/sda1
/dev/sda2
/dev/sda3
...
/dev/sdb
返回的这些信息中 sda 和 sdb 分别代表了两块硬盘设备。其中带编号的 sda 1/2/3 说明该设备已经有多个分区,而不带编号的 /dev/sdb 是未分区的存储设备。每一个设备可以有多个分区,1-4 为主分区,5+ 是逻辑分区。

分区
下面,我们用 fdisk 命令对未分区的 /dev/sdb 做分区操作,

$ fdisk /dev/sdb
运行完成上面的命令会进入分区系统,之后需要通过若干个子命令进行分区操作,在这操作的过程中,每一个步骤系统都会有详情的提示,我们输入第一个命令 "n" 进入分区。

n - 按下 “n” 之后会进入分区状态,下一步要填写分区的类型,有三个类型可以选择 p 主分区、e 扩展分区、l 逻辑分区,我们选择 “p”。
p - 选择 “p 主分区” 之后,需要填写分区的编号 1-4。
1 - 完成编号的填写就剩最后一个步骤了,那就是分区的大小。
+1024M 我们选择1G的大小。
操作完上面的步骤,就完成了一次分区操作,我们可以按 p 查看当前磁盘的分区状态。

如果磁盘还剩空间,那么接着按 n 命令,重复上面的步骤。

最后如果所有的分区都完成了,按 w 可以保存,如果对分区的结果不满意,那么按 q 可以退出分区操作。

格式化分区
分成完成之后,需要做一次格式操作,使用 mke2fs 工具。

mke2fs -t ext4 /dev/sda5 // -t 指定文件系统类型 | ext4 是 Linux 流行的文件系统
挂载
挂载是个有意思的事情,刚接触 Linux 不久的同学们经常们经常会有困惑,为什么插了 U 盘在系统上没显示,那是因为没有挂载。挂载就是让设备跟某个目录关联,然后通过这个目录可以进入、读取 ... 设备的内容。我们刚刚分区出来的 空磁盘,也需要做挂载操作。

挂载使用的命令是 mount,如果不加任何参数使用 mount ,会返回当前系统已经完成挂载的设备信息。

$ mount
/dev/simfs on / type simfs (rw,relatime,usrquota,grpquota)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,mode=755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
...
我们做个实例,挂载我们刚刚分区出来的一个主分区 /dev/sdb1

mkdir ~/newpath
mount /dev/sdb1 ~/newpath
挂载之后 ~/newpath 关联的就是 /dev/sdb1 设备。

/etc/fstab
通过 mount 命令挂载的磁盘,只是临时的,当系统重启之后就会消失,如果想要实现永久的挂载,那么要把挂载信息配置到 /etc/fstab 文件里面。格式如下:

UUID=c61117ca-9176-4d0b-be4d-1b0f434359a7  /root/f  ext4  defaults  0  0

/*
 1. UUID
 2. 挂载点
 3. 文件系统
*/
UUID 的获取可以通过这个命令 blkid /dev/sdb1。

配置成功之后,运行 mount -a 加载 /etc/fstab 文件。

 

详解二:

、             通过Fdisk查看系统分区详细信息:

Fdisk –l   详解:

[root@jetsenLin ~]# fdisk -l

 

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

注释:这个硬盘的大小是10.7GB,有255个磁面,63个扇区,1305磁柱(cylinders)

每个 cylinder(磁柱)的容量是 8225280 bytes=8225.280 K(约为)=8.225280M(约为);

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14        1305    10377990   8e  Linux LVM

 

id和System 表示的是一个意思,id看起来不太直观,我们要在fdisk 一个分区时,通过指定id来确认分区类型;比如 7表示的就NTFS 分区;这个在fdisk 中要通过t功能来指定。下面的部分会提到;

 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

Disk /dev/sdb doesn't contain a valid partition table

说明: 硬盘分区的表示:在Linux 是通过hd*x 或 sd*x 表示的:

其中 * 表示的是a、b、c ... ...

另外 x 表示的数字 1、2、3 ... ...

hd大多是IDE硬盘;sd大多是SCSI或移动存储; 引导(Boot):表示引导分区,在上面的例子中 sda1 是引导分区;

Start (开始):表示的一个分区从X cylinder(磁柱)开始;

End (结束):表示一个分区到 Y cylinder(磁柱)结束;

 

2、             学会使用fdisk帮助功能:

[root@jetsenLin ~]# fdisk /dev/sda

 

The number of cylinders for this disk is set to 1305.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

 

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   --创建一个新的空白DOS分区表

   p   print the partition table                ---打印分区表

   q   quit without saving changes            ---退出不保存设置

   s   create a new empty Sun disklabel        ---

   t   change a partition's system id           ---改变分区的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):

3、             通过Fdisk对磁盘分区进行操作:

Fdisk 创建分区:

[root@jetsenLin ~]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remain in memory only,

until you decide to write them. After that, of course, the previous

content won't be recoverable.

 

 

The number of cylinders for this disk is set to 2610.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

 

Command (m for help): n          ---输入m会有帮助信息出来,输入n不打印帮助信息

Command action

   e   extended

   p   primary partition (1-4)      ---指定分区类型  e为扩展分区   p为主分区

p

Partition number (1-4): 1           ---定义分区数量   --主分区最多只能有四个

First cylinder (1-2610, default 1): 1   ---设定起始分区的位置

Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):

Using default value 2610            ---设定结束分区的位置

 

Command (m for help): w           ---保存刚才的配置信息。

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

[root@jetsenLin ~]#

 

 Fdisk 删除分区:

 

[root@jetsenLin ~]# fdisk /dev/sdb   

 

The number of cylinders for this disk is set to 2610.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

 

Command (m for help): d      ---d 是代表删除,并且会列出当前磁盘的分区数。

Selected partition 1

 

Command (m for help): p      ----p 是代表删除后,显示磁盘还有几个剩余的分区。

 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System    ----已经没有分区了

 

Command (m for help): w                  ----保存刚才的操作并且生效

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.  

The kernel still uses the old table.

The new table will be used at the next reboot.

这里报了一错误,分区表正在使用,删除再下次启动生效

Syncing disks.        ---同步新的磁盘信息

[root@jetsenLin ~]# fdisk -l /dev/sdb

 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

 

通过fdisk 命令来创建一指定大小的分区并增加一个分区

Fdisk n

创建分区:

[root@jetsenLin ~]# fdisk /dev/sdb

 

The number of cylinders for this disk is set to 2610.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

 

Command (m for help): n            ---创建分区

Command action

   e   extended

   p   primary partition (1-4)      --指定分区类型为主分区

p

Partition number (1-4): 1           --指定其实分区号

First cylinder (1-2610, default 1): 1   --指定起始柱面号

Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): 1024 ---指定终止柱面号

 

Command (m for help): w            ---保存分区配置信息

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

增加分区:

[root@jetsenLin ~]# fdisk /dev/sdb      -----增加分区

 

The number of cylinders for this disk is set to 2610.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

 

Command (m for help): n       ---分区类型

Command action

   e   extended

   p   primary partition (1-4)    ---还是指定主分区

p

Partition number (1-4): 1          ---分区号,我指定1。

Partition 1 is already defined.  Delete it before re-adding it. 

–提示分区号1已经存在,删除后操作

Command (m for help): n          --我们重新创建分区

Command action

   e   extended

   p   primary partition (1-4)     --指定分区类型

p

Partition number (1-4): 2          ---因为分区1已经存在,所以我们指定分区2,可通过。

First cylinder (1025-2610, default 1025):       ---指定起始礠柱号,默认是上一分区后一号。

Using default value 1025

Last cylinder or +size or +sizeM or +sizeK (1025-2610, default 2610): 2000   --指定终止礠柱号。

 

Command (m for help): w                   ---保存分区配置

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

[root@jetsenLin ~]#

 

通过fdisk 命令来来修改现有分区类型

   Fdisk 通过t参数来指定

 查看分区类型

[root@jetsenLin ~]# fdisk -l /dev/sdb   查看分区信息,类型是Linux,id是83

 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1024     8225248+  83  Linux

/dev/sdb2            1025        2000     7839720   83  Linux

 

修改分区类型

[root@jetsenLin ~]# fdisk /dev/sdb

 

The number of cylinders for this disk is set to 2610.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

 

Command (m for help): t                              ---进入修改分区类型

Partition number (1-4): 1                              ---指定需要修改的分区号

Hex code (type L to list codes): 6                        ---指定分区号为6,也就是FAT16

注意:查看分区类型的代码,在这里可以输入L查看就可以了

Changed system type of partition 1 to 6 (FAT16)

 

Command (m for help): w                              ---保存

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the next reboot.

 

WARNING: If you have created or modified any DOS 6.x

partitions, please see the fdisk manual page for additional

information.

Syncing disks.

 

[root@jetsenLin ~]# fdisk -l /dev/sdb        ---我们看到已经FAT16,并且ID也改成6了。

 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1024     8225248+   6  FAT16

/dev/sdb2            1025        2000     7839720   83  Linux

[root@jetsenLin ~]#

 

 

4、             对分区进行格式化及加载:

对分区进行格式化的命令如下等,mkfs后面所接的代表的是将要格式化成的文件系统类型:

mkfs.bfs

mkfs.ext2

mkfs.ext3

mkfs.jfs

mkfs.msdos

mkfs.vfat

mkfs.cramfs

mkfs.minix

mkfs.reiserfs

mkfs.xfs

 

格式化分区:

 [root@jetsenLin ~]# mkfs.ext4 /dev/sdb1          ---格式化分区类型为ext4

mke4fs 1.41.5 (23-Apr-2009)

Filesystem label=                  ---我们没有指定卷标,就没有

OS type: Linux                    ---操作系统类型

Block size=4096 (log=2)             --单个块的大小

Fragment size=4096 (log=2)          --片大小

1310720 inodes, 5241198 blocks

262059 blocks (5.00%) reserved for the super user

First data block=0     

Maximum filesystem blocks=0

160 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

        4096000

 

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 27 mounts or

180 days, whichever comes first.  Use tune4fs -c or -i to override.

 

挂载磁盘:(临时挂载)

[root@jetsenLin ~]# mkdir /data             --创建挂载目录点

[root@jetsenLin ~]# mount  /dev/sdb1 /data  --将/dev/sdb1 挂载到/data

 

验证是否成功挂载

[root@jetsenLin ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol00

                      7.7G  3.1G  4.2G  43% /

/dev/sda1              99M   12M   82M  13% /boot

tmpfs                 506M     0  506M   0% /dev/shm

/dev/sdb1              20G   16K   20G   1% /data     --我们看到已经成功挂载了。

[root@jetsenLin ~]#

 

挂载磁盘:(永久挂载)

   通过vi编辑器编辑/etc/fstab文件,内容如下,(红色部分是刚添加上去的):

 

挂载路径              挂载的分区          文件系统  挂载参数     是否要备份   自检顺序

/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1

LABEL=/boot             /boot                   ext3    defaults        1 2

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0

/data                   /dev/sdb1                ext4    default         0 0

 

第四列挂载参数:通过查看man mount 来查看

第五列是否要备份:(0为不备份,1为要备份, 一般情况下不用做备份)

第六列自检程序  (0为不自检,1或2为要自检,如果是根分区要设置1,其它分区只能是2)

 

============ End

三:du命令

Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是查看当前指定文件或目录(会递归显示子目录)占用磁盘空间大小,还是和df命令有一些区别的.

1.命令格式:

du [选项][文件]

2.命令功能:

显示每个文件和目录的磁盘使用空间。

3.命令参数:

-a或-all  显示目录中个别文件的大小。   

-b或-bytes  显示目录或文件大小时,以byte为单位。   

-c或--total  除了显示个别目录或文件的大小外,同时也显示所有目录或文件的总和。 

-k或--kilobytes  以KB(1024bytes)为单位输出。

-m或--megabytes  以MB为单位输出。   

-s或--summarize  仅显示总计,只列出最后加总的值。

-h或--human-readable  以K,M,G为单位,提高信息的可读性。

-x或--one-file-xystem  以一开始处理时的文件系统为准,若遇上其它不同的文件系统目录则略过。 

-L<符号链接>或--dereference<符号链接> 显示选项中所指定符号链接的源文件大小。   

-S或--separate-dirs   显示个别目录的大小时,并不含其子目录的大小。 

-X<文件>或--exclude-from=<文件>  在<文件>指定目录或文件。   

--exclude=<目录或文件>         略过指定的目录或文件。    

-D或--dereference-args   显示指定符号链接的源文件大小。   

-H或--si  与-h参数相同,但是K,M,G是以1000为换算单位。   

-l或--count-links   重复计算硬件链接的文件。  

 

4.使用实例:

实例1:显示目录或者文件所占空间 

命令:du

输出:

复制代码
44      ./xml
60      ./mem
8       ./thread
188     ./glog/glog-0.3.3/src/glog
32      ./glog/glog-0.3.3/src/base
96      ./glog/glog-0.3.3/src/windows/glog
124     ./glog/glog-0.3.3/src/windows
780     ./glog/glog-0.3.3/src
8       ./glog/glog-0.3.3/vsprojects/logging_unittest
8       ./glog/glog-0.3.3/vsprojects/logging_unittest_static
12      ./glog/glog-0.3.3/vsprojects/libglog_static
12      ./glog/glog-0.3.3/vsprojects/libglog
44      ./glog/glog-0.3.3/vsprojects
376     ./glog/glog-0.3.3/m4
248     ./glog/glog-0.3.3/.deps
32      ./glog/glog-0.3.3/doc
7180    ./glog/glog-0.3.3/.libs
8       ./glog/glog-0.3.3/packages/rpm
48      ./glog/glog-0.3.3/packages/deb
68      ./glog/glog-0.3.3/packages
17828   ./glog/glog-0.3.3
17836   ./glog
60      ./sort
43687
复制代码
说明:

只显示当前目录下面的子目录的目录大小和当前目录的总的大小,最下面的43687为当前目录的总大小

 

实例2:显示指定文件所占空间

命令:du log2012.log

输出:

root@ubuntu:/home/work/test# du a.out 
16      a.out
root@ubuntu:/home/work/test# 
 

实例3:查看指定目录的所占空间

命令:du scf

输出:

root@ubuntu:/home/work/test# du gdb
80      gdb
root@ubuntu:/home/work/test# 
 

实例4:显示多个文件所占空间

命令:du log30.tar.gz log31.tar.gz

输出:

root@ubuntu:/home/work/test# du a.out main.cpp 
16      a.out
4       main.cpp
root@ubuntu:/home/work/test# 
 

实例5:只显示总和的大小

命令:du -s

输出:

root@ubuntu:/home/work/test# du -s
383124  .
root@ubuntu:/home/work/test# du -s redis
39784   redis
root@ubuntu:/home/work/test# 
 

实例6:方便阅读的格式显示

命令:du -h test

输出:

复制代码
root@ubuntu:/home/work/test# du -h log
16K     log/boost_log/log
6.8M    log/boost_log
1.1M    log/logouts/test
1.1M    log/logouts
7.9M    log
root@ubuntu:/home/work/test# 
复制代码
 

实例7:文件和目录都显示

命令:du -ah log

输出:

复制代码
root@ubuntu:/home/work/test# du -ah log
4.0K    log/main.cpp
4.0K    log/Log.h
12K     log/boost_log/log/sign_2016-06-21_20.000.log
16K     log/boost_log/log
4.0K    log/boost_log/main.cpp
8.0K    log/boost_log/mainEx.cc
2.5M    log/boost_log/a.out
3.9M    log/boost_log/Logger.o
4.0K    log/boost_log/Logger.h
448K    log/boost_log/main.o
4.0K    log/boost_log/Makefile
4.0K    log/boost_log/Logger.cpp
6.8M    log/boost_log
8.0K    log/Log.cpp
4.0K    log/logouts/test/x.txt
1.1M    log/logouts/test/20160614.log
1.1M    log/logouts/test
1.1M    log/logouts
7.9M    log
root@ubuntu:/home/work/test# 
复制代码
 

实例8:显示几个文件或目录各自占用磁盘空间的大小,还统计它们的总和

命令:du -c log30.tar.gz log31.tar.gz

输出:

复制代码
root@ubuntu:/home/work/test# du -c md5 log 
7316    md5
16      log/boost_log/log
6928    log/boost_log
1116    log/logouts/test
1120    log/logouts
8068    log
15384   total
root@ubuntu:/home/work/test# 
复制代码
说明:

加上-c选项后,du不仅显示两个目录各自占用磁盘空间的大小,还在最后一行统计它们的总和。

 

实例9:按照空间大小排序

命令:du|sort -nr|more

输出:

复制代码
root@ubuntu:/home/work/test/log# du |sort -nr|more
8068    .
6928    ./boost_log
1120    ./logouts
1116    ./logouts/test
16      ./boost_log/log
root@ubuntu:/home/work/test/log# 
复制代码
 

实例10:输出当前目录下各个子目录所使用的空间

命令:du -h  --max-depth=1

输出:

复制代码
root@ubuntu:/home/work/test# du -h  --max-depth=1
7.9M    ./log
44K     ./xml
60K     ./mem
8.0K    ./thread
18M     ./glog
60K     ./sort
296M    ./python
39M     ./redis
80K     ./gdb
44K     ./minmaxheap
6.7M    ./async
7.2M    ./md5
28K     ./move
375M    .
root@ubuntu:/home/work/test# 

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值