Display directory size


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Display directory size
# 1  
Old 11-23-2008
Display directory size

Hi all,

Is there any built in function that can display the content of a directory showing the size of directories?
I want to see the content of a directory without recursion. I don't want to see the content of all subdirectories.
I want to see the contained files with their size and the contained directories with their total size (including everything they contain).

1) I cannot get ls to do that.
2) With du, I can only get either the total size of one directory or the total size of all subdirectories (even several levels under).

Thanks in advance
Santiago

Here is an example of a directory tree with what I get with ls, then what I get with du and finally what I'd like to get:
Code:
~$ ls -lR
.:
-rw-r--r-- 1 santiago santiago   88 2008-11-23 10:34 file
drwxr-xr-x 4 santiago santiago 4096 2008-11-23 10:34 folderA
drwxr-xr-x 2 santiago santiago 4096 2008-11-23 10:35 folderB

./folderA:
-rw-r--r-- 1 santiago santiago   31 2008-11-23 10:34 fileA
drwxr-xr-x 2 santiago santiago 4096 2008-11-23 10:34 folderC
drwxr-xr-x 2 santiago santiago 4096 2008-11-23 10:34 folderD

./folderA/folderC:
-rw-r--r-- 1 santiago santiago  269 2008-11-23 10:34 fileC

./folderA/folderD:
-rw-r--r-- 1 santiago santiago  509 2008-11-23 10:34 fileD

./folderB:
-rw-r--r-- 1 santiago santiago  623 2008-11-23 10:35 fileB

~$ du
623    ./folderB
269    ./folderA/folderC
509    ./folderA/folderD
809    ./folderA
1520   .

~$ whatidlike
file       88
folderA   809
folderB   623

# 2  
Old 11-23-2008
Did you try:

Code:
du -s <glob>

For example:

Code:
$ ls -l
total 10220
drwxr-xr-x+  7 sysadmin None       0 Nov  3 13:30 ast
drwxr-xr-x+  2 sysadmin None       0 Nov  3 11:56 nawk
drwxr-xr-x+ 13 sysadmin None       0 Nov  3 11:26 zsh-4.3.8
-rwx------+  1 sysadmin None 2570984 Nov  3 11:15 zsh-4.3.8-doc.tar.bz2
-rwx------+  1 sysadmin None 2656376 Nov  3 11:15 zsh-4.3.8.tar.bz2
drwxr-xr-x+ 13 sysadmin None       0 Nov  3 13:23 zsh-4.3.9
-rw-r--r--   1 sysadmin None 2570995 Nov  3 13:15 zsh-4.3.9-doc.tar.bz2
-rw-r--r--   1 sysadmin None 2659602 Nov  3 13:17 zsh-4.3.9.tar.bz2
$ du -ks *
138639  ast
1331    nawk
26518   zsh-4.3.8
2512    zsh-4.3.8-doc.tar.bz2
2596    zsh-4.3.8.tar.bz2
26534   zsh-4.3.9
2512    zsh-4.3.9-doc.tar.bz2
2600    zsh-4.3.9.tar.bz2

# 3  
Old 11-23-2008
great job.
thank you.
# 4  
Old 11-26-2008
Quote:
Originally Posted by radoulov
Did you try:

Code:
du -s <glob>

For example:

Code:
$ ls -l
total 10220
drwxr-xr-x+  7 sysadmin None       0 Nov  3 13:30 ast
drwxr-xr-x+  2 sysadmin None       0 Nov  3 11:56 nawk
drwxr-xr-x+ 13 sysadmin None       0 Nov  3 11:26 zsh-4.3.8
-rwx------+  1 sysadmin None 2570984 Nov  3 11:15 zsh-4.3.8-doc.tar.bz2
-rwx------+  1 sysadmin None 2656376 Nov  3 11:15 zsh-4.3.8.tar.bz2
drwxr-xr-x+ 13 sysadmin None       0 Nov  3 13:23 zsh-4.3.9
-rw-r--r--   1 sysadmin None 2570995 Nov  3 13:15 zsh-4.3.9-doc.tar.bz2
-rw-r--r--   1 sysadmin None 2659602 Nov  3 13:17 zsh-4.3.9.tar.bz2
$ du -ks *
138639  ast
1331    nawk
26518   zsh-4.3.8
2512    zsh-4.3.8-doc.tar.bz2
2596    zsh-4.3.8.tar.bz2
26534   zsh-4.3.9
2512    zsh-4.3.9-doc.tar.bz2
2600    zsh-4.3.9.tar.bz2


You can also use :

#du -sh *

it will give you batter o/p...
# 5  
Old 11-26-2008
Quote:
Originally Posted by Reboot
it will give you batter o/p...
Thanks Reboot,
What is o/p?

Actually, I don't like the switch h because it makes it impossible to visually compare sizes.
# 6  
Old 11-26-2008
Quote:
Originally Posted by Reboot
You can also use :

#du -sh *

it will give you batter o/p...
... if your implementation of du supports it:

Code:
$ du -hs *
du: illegal option -- h
usage: du [-a][-d][-k][-r][-o|-s][-L] [file ...]
/usr/ccs/bin/what /usr/bin/du
/usr/bin/du:
        SunOS 5.8 Generic 109803-01 June 2000
$ /usr/xpg4/bin/du -hs
/usr/xpg4/bin/du: illegal option -- h
usage: du [-a][-k][-r][-s][-x] [file ...]

or:

Code:
$ du -hs *
du: illegal option -- h
usage: du [-a|-s] [-kbrx] [-t type] [name ...]
$ what /usr/bin/du
/usr/bin/du:
         $Revision: B.11.11_LR
         Thu Oct 26 23:49:27 PDT 2000 $

Quote:
What is o/p?
output, I suppose ...
# 7  
Old 11-26-2008
Thanks radoulov
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. UNIX for Beginners Questions & Answers

UNIX commands to display the biggest file by size in a directory

Hello guys, Please i need to know the biggest files in my directory let's say$ >du -h | egrep 'M|G|G' 195M ./TMP 3.6M ./TP_DEC2012 146G . But here the result it's giving me the biggest directory in the path. Actually i want to know the biggest file in 146G . Can anyone... (6 Replies)
Discussion started by: gillesi
6 Replies

3. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

4. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

5. UNIX for Dummies Questions & Answers

How to display only Owner and directory/sub directory names under particular root

hai, I am new to Unix, I have a requirement to display owner name , directory or sub directory name, who's owner name is not equal to "oasitqtc". (here "oasitqtc" is the owner of the directory or sub directory.) i have a command (below) which will display all folders and sub folders, but i... (6 Replies)
Discussion started by: gagan4599
6 Replies

6. UNIX for Dummies Questions & Answers

Display all directory/sub directory with occupied space?

Hello, I am using Red Hat linux system. I see my /work directory has used space 300GB. But there are so many sub directory under /work. I want to list each direcotry and under all subdirectory. But i want to know how much space occupied by each directory. What kind of command i can use to... (3 Replies)
Discussion started by: govindts
3 Replies

7. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

8. UNIX for Dummies Questions & Answers

du -k . display size wise

Hi, I want to display all the directories with ascending order in size. For example, $ du -k . 1111111 ./dir1 222222222 ./dir2 333333333 ./dir3 444444444 ./dir4 How do i get the above desired result with du -k . command? Thanks (1 Reply)
Discussion started by: welldone
1 Replies

9. UNIX for Dummies Questions & Answers

Display size

Hi Friends, I'm a Oracle Dba first time working in Solaris, i have worked on linux (redhat). I want to see the size of the particular directory e.g oracle and also the size of the database files. Thank you (1 Reply)
Discussion started by: shaan_dmp
1 Replies

10. UNIX for Dummies Questions & Answers

Display Directory Size - DF?

How can I display the size of a directory and contents witin a directory df only gives me the mounts (3 Replies)
Discussion started by: t4st33@mac.com
3 Replies
Login or Register to Ask a Question