linux查看磁盘空间及文件大小

上一篇 / 下一篇  2015-02-28 13:42:56 / 个人分类:linux

1、du -sh 查看当前文件夹大小

du -sh * | sort -n 统计当前文件夹(目录)大小,并按文件大小排序

附送:
du -sk filename 查看指定文件大小


2、 Linux:ls以K、M、G为单位查看文件大小

#ls -lhs

举例比较:

# ls
cuss.war nohup.out

# ls -l
total 30372
-rw-r--r-- 1 root root 31051909 May 24 10:07 cuss.war
-rw------- 1 root root 0 Mar 20 13:52 nohup.out

# ls -lh
total 30M
-rw-r--r-- 1 root root 30M May 24 10:07 cuss.war
-rw------- 1 root root 0 Mar 20 13:52 nohup.out

# ll -h
total 30M
-rw-r--r-- 1 root root 30M May 24 10:07 cuss.war
-rw------- 1 root root 0 Mar 20 13:52 nohup.out

# ls -lhs
总计 28G
15G -rw-r--r-- 1 root root 15G 06-04 14:35 all.txt
8.0K -rwx--x--x 1 root root 632 06-04 15:57 hash.pl











linux下查看磁盘空间
2012-07-20 08:58:21     我来说两句      
收藏  我要投稿

如果要查看磁盘还剩多少空间,当然是用df的命令了。
[root@localhost ~]# df -h 
文件系统             容量 已用 可用 已用% 挂载点 
/dev/sda2              14G   11G 2.6G 82% / 
/dev/sda1              99M   14M   81M 14% /boot 
tmpfs                 442M 275M 168M 63% /dev/shm 
/dev/mapper/vg_test-lv_test 
                       24M 1.3M   21M   6% /mnt/lvm 
[root@localhost ~]#
当然你可能并不关系磁盘还剩余多少空间,你是需要知道当前的文件夹下的磁盘使用情况:
[root@localhost ~]# du --max-depth=1 -h 
24K     ./.gnome   www.2cto.com  
8.0K    ./.eggcups 
8.0K    ./.config 
136K    ./.gnome2 
16K     ./.chewing 
8.0K    ./.gnome2_private 
8.0K    ./.Trash 
224K    ./.gstreamer-0.10 
28K     ./Desktop 
48K     ./.nautilus 
48K     ./.metacity 
240K    ./.scim 
3.4M    ./.mozilla 
1012K   ./.kde 
12K     ./.superkaramba 
40K     ./.local 
8.0K    ./.qt 
272K    ./.gconf 
32K     ./.mcop 
16K     ./.redhat 
1.7M    ./.thumbnails 
8.0K    ./.gconfd 
7.5M    . 
[root@localhost ~]#
看上面使用了du --max-depth=1 -h的命令来查找磁盘的使用情况,因为后面没有跟路径,它就默认是当前的路径。这个命令的-h参数是为了方便你读懂每个文件的大小,如果没有这个参数显示 的文件大小就没有k,M,G等。执行命令后,前面n-1行的是该目录下每个文件夹的大小。最后一行显示的是该目录总的大小。
然后你会说不在乎该目录下每个文件的大小,你只想知道其中某一个文件(文件夹)的大小,那么有没有办法呢?当然你应该记得,我一直强调的,方法总比问题多,这儿也不例外。
请看下面的例子:
[root@localhost ~]# du -sh 
7.5M    .   www.2cto.com  
[root@localhost ~]#
聪明的你一定发现了这里显示的大小和上面最后一行的大小是一样的。这就是说这里显示的大小是该目录的总大小。
我知道你心里在冷笑,不是方法比问题多吗?这里说的也只有一个答案。当然,我不会让你失望的。另一个方法比较土,但是还是可以解决问题的。
[root@localhost ~]# du -h --max-depth=0 
7.5M    . 
[root@localhost ~]#
我想告诉你的是man手册里面已经告诉了:--max-depth=0的功能和-s的功能是一样的。
当然你也可以通过sed打印最后du -h --max-depth=1一行来解决问题,但我并不推荐。
这里涉及到一个原则,尽量使用命令提供选项的原始功能。如果命令没有提供该功能,才需要我们自己使用grep,sed,awk来选取我们需要的行。
当然du命令后面可以跟文件路径,来查看指定路径的大小的。
[root@localhost ~]# du -sh /opt/oracle 
5.6G    /opt/oracle 
[root@localhost ~]#
如果磁盘过大,那么查看文件大小就比较忙,请等一会,呵呵。

TAG:

 

评分:0

我来说两句

Open Toolbar