Manage Directory Size On Linux – Total Number Of Files

By | August 28, 2009

Display or list total number of files on a current directory with users in Linux

It would good to manage the directory size on Linux to make all the applications and system to work smoothly with a good performance.Manage directory size on Linux is easier with a set of commands.

Ina small condition, suppose we have a common share on company and all people on the organization have access/write to the share. At a point Administrator need to see the users usage on the share and like to find out the file count per user or total file on the directory,directory size on Linux.

Use the following commands to manage directory size on Linux,

Both commands displays the total count of the files created by each user.

# find /home -type f -printf “%un” | awk ‘{count[$0]++}END{for(i in count)print i, count[i]}’

Out Put :

root 9 melbin 7

# find /home -type f -print0 | xargs -0 stat -c %U | sort | uniq -c

Out Put:

7 melbin 9 root

We can also use a simple command to see the total count on the directory,

# ls -l /home | wc -l

Example:

6

# ls -la /home | wc -l (Display hidden files)

Example:

8

Command find the number of files in a directory, and it will send o/p as pipe to the wc -l, which outputs the number of lines in its input.

*Count will include “. (present) and ..(previous)” directory.

To Find – Directory/File Resource Usage,

# du -sh /home (Display Total Size)

Example:

456K /home/

# du -ah /home (Display Each Files Size)

Example:

4.0K /home/melbin/.mozilla/extensions

4.0K /home/melbin/.mozilla/plugins

Finding the Big Files

# find / -size +1000000c -ls (Display files having more that 1 million characters)

# find /home/melbin -size +1M (Display files having more than 1MB)

# find /home/melbin -size +1k (Display files having more than 1KB)

Example:

687458 4 drwx—— 5 melbin melbin 4096 Aug 29 07:37 /home/melbin/

687459 4 drwxr-xr-x 4 melbin melbin 4096 Nov 11 2008 /home/melbin/.mozilla

687460 4 drwxr-xr-x 2 melbin melbin 4096 Nov 11 2008 /home/melbin/.mozilla/extensions

To Find – Total Hardisk Usage,

# df -h (Display the Present Usage)

Example:

Filesystem Size Used Avail Use% Mounted on

/dev/sda11 37G 12G 24G 34% /

/dev/sda9 487M 43M 419M 10% /boot

tmpfs 502M 0 502M 0% /dev/shm

# df -hi (List Inode information instead of block usage)

Example:

Filesystem Inodes IUsed IFree IUse% Mounted on

/dev/sda11 9.6M 269K 9.3M 3% /

/dev/sda9 126K 73 126K 1% /boot

tmpfs 126K 1 126K 1% /dev/shm

Cheers !

Melbin Mathew

www.talk2melbin.com

Melbin Mathew

I am Melbin Mathew, Systems Engineer from Kerala, India. I live with my parents, daughter and my wonderful wife. I graduated in 2004 with a bachelor’s degree in Electronics and Hardware from Mahatma Gandhi University, Kottayam and completed certification in MCITP, RHCE, CCNA, VCP ...Read More
Category: Linux

About Melbin Mathew

I am Melbin Mathew, Systems Engineer from Kerala, India. I live with my parents, daughter and my wonderful wife. I graduated in 2004 with a bachelor’s degree in Electronics and Hardware from Mahatma Gandhi University, Kottayam and completed certification in MCITP, RHCE, CCNA, VCP ...Read More