如何在Linux下查看分区和剩余空间大小

如何在Linux下查看分区和剩余空间大小,第1张

df -hl 查看磁盘剩余空间

du -sm 文件夹

返回该文件夹总M数

更多功能请查看:

df --help

du --help

du -sh (这个目录的名字)是查这个目录的大小

使用du命令可以查看目录,例如查看/home/kuuyee目录占用磁盘空间大小可以使用下面的命令:

# du /home/kuuyee -sh

我的home目录下有上百个构建项目,一个一个的差看目录占用情况太麻烦了用命令:

#du /home --max-depth=1 -h

这样的话就吧所有的子目录的磁盘占用情况都列出来了!这里的--max-depth参数代表着要列出目录的深度,如果要列出两级目录就设置为2,以此类推。

如果想吧结果输出到文件里可以这样:# du /home --max-depth=1 -h >disk_status.txt

用df -h 查每个根下面的目录的分区大小 就可以知道了

用法:du [选项]… [文件]…

或:du [选项]… –files0-from=F

总结每个<文件>的磁盘用量,目录则取总用量。

df命令是linux系统以磁盘分区为单位查看文件系统,可以加上参数查看磁盘剩余空间信息,命令格式:

df -hl

显示格式为: 

文件系统 容量 已用 可用 已用% 挂载点 

FilesystemSize Used Avail Use% Mounted on

/dev/hda2 45G 19G 24G 44% /

/dev/hda1 494M 19M 450M 4% /boot

/dev/hda6 4.9G 2.2G 2.5G 47% /home

/dev/hda5 9.7G 2.9G 6.4G 31% /opt

none 1009M 0 1009M 0% /dev/shm

/dev/hda3 9.7G 7.2G 2.1G 78% /usr/local

/dev/hdb2 75G 75G 0 100% /

/dev/hdb2 75G 75G 0 100% /

以上面的输出为例,表示的意思为:

HD硬盘接口的第二个硬盘(b),第二个分区(2),容量是75G,用了75G,可用是0,因此利用率是100%, 被挂载到根分区目录上(/)。

例子

1)查看文件大小

查看当前文件夹下所有文件大小(包括子文件夹)

du -sh

# du -h

15M ./package

16K ./.fontconfig

4.0K./.cache

5.1M./.rpmdb

20M .

查看指定文件夹下所有文件大小(包括子文件夹)

# du -h ftp

3.8Gftp/sanya/doc

3.8Gftp/sanya

4.0Kftp/testftp/doc

1.4Mftp/testftp

875Mftp/platform/doc/002-录像

27M ftp/platform/doc/001-PDF

5.2Mftp/platform/doc/BBFlash

1.2Gftp/platform/doc/003-录音

2.1Gftp/platform/doc

2.1Gftp/platform

4.0Kftp/pmo/doc

20K ftp/pmo

36M ftp/uf/doc/innovate-201207

36M ftp/uf/doc

36M ftp/uf

446Mftp/code/doc

446Mftp/code

6.3Gftp

查看指定文件大小

# du -h ./package/compat-libstdc++-33-3.2.3-69.el6.x86_64.rpm

184K./package/compat-libstdc++-33-3.2.3-69.el6.x86_64.rpm

查看指定文件夹大小

# du -hs ftp

6.3Gftp

统计总数大小

du -sh xmldb/

du -sm * | sort -n //统计当前目录大小 并安大小 排序

du -sk * | sort -n

du -sk * | grep guojf //看一个人的大小

du -m | cut -d "/" -f 2 //看第二个/ 字符前的文字

查看此文件夹有多少文件 /*/*/* 有多少文件

du xmldb/

du xmldb/*/*/* |wc -l

40752

解释:

wc [-lmw]

参数说明:

-l :多少行

-m:多少字符

-w:多少字

参数含义如下:

-s 对每个Names参数只给出占用的数据块总数。

-a 递归地显示指定目录中各文件及子孙目录中各文件占用的数据块数。若既不指定-s,也不指定-a,则只显示Names中的每一个目录及其中的各子目录所占的磁盘块数。

-b 以字节为单位列出磁盘空间使用情况(系统缺省以 k 字节为单位)。

-k 以1024字节为单位列出磁盘空间使用情况。

-c 最后再加上一个总计(系统缺省设置)。

-l 计算所有的文件大小。

可通过系统自带的命令查看,也可以通过第三方软件查看,具体如下:

1.

查看文件大小

查看当前文件夹下所有文件大小(包括子文件夹)

du

-sh 

#

du

-h

15M

./package

16K

./.fontconfig

4.0K

./.cache

5.1M

./.rpmdb

20M

. 

2.

df

-h

Df命令是linux系统以磁盘分区为单位查看文件系统,可以加上参数查看磁盘剩余空间信息,命令格式:

df

-hl

显示格式为:

文件系统

容量

已用

可用

已用%

挂载点

Filesystem

Size

Used

Avail

Use%

Mounted

on

/dev/hda2

45G

19G

24G

44%

/

/dev/hda1

494M

19M

450M

4%

/boot

/dev/hda6

4.9G

2.2G

2.5G

47%

/home

3.

cfdisk来自于util-linux的软件包;

cfdisk也是一款不错的分区工具;在有些发行版中,此工具已经从util-linux包中剔除;cfdisk简单易用是他的特点;和DOS中的fdisk相似;在本标题中,我们只来解说如何查看机器的中的磁盘分区状况及所用的文件系统等;

查看磁盘分区的用法cfdisk

-Ps磁盘设备名;

比如

[root@localhost

beinan]cfdisk

-Ps

[root@localhost

beinan]cfdisk

-Ps

/dev/hda

[root@localhost

beinan]cfdisk

-Ps

Partition

Table

for

/dev/hda

每个扇区大小为0, 一共350个柱面,起始柱面是1000,扇区数量300.

详细如下:

fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device

-b sectorsize

Specify the sector size of the disk. Valid values are 512, 1024, 2048 or 4096. (Recent kernels know the sector size. Use this only on old kernels or to override the kernel's ideas.) Since util-linux-2.17, fdisk differentiates between logical and physical sector size. This option changes both sector sizes to sectorsize.

-c[=mode]

Specify the compatiblity mode, 'dos' or 'nondos'. The default is non-DOS mode. For backward compatibility, it is possible to use the option without the <mode>argument -- then the default is used. Note that the optional <mode>argument cannot be separated from the -c option by a space, the correct form is for example '-c=dos'.

-C cyls

Specify the number of cylinders of the disk. I have no idea why anybody would want to do so.

-H heads

Specify the number of heads of the disk. (Not the physical number, of course, but the number used for partition tables.) Reasonable values are 255 and 16.

-S sects

Specify the number of sectors per track of the disk. (Not the physical number, of course, but the number used for partition tables.) A reasonable value is 63.


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7379690.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-05
下一篇2023-04-05

发表评论

登录后才能评论

评论列表(0条)

    保存