How To Find Large Files and Directories in Unix

Sometimes we need to find larger files in a file system when theres is a disk space issue.

This example finds all the files under /etc directory which are larger than 1000k:

geobaby@ubuntu:~$ find /etc -size +1000k

If you look at the file, the size if above 1000k:

geobaby@ubuntu:~$ ls -l /etc/brltty/zh-tw.ctb
-rw-r–r– 1 root root 1368836 2010-08-12 05:20 /etc/brltty/zh-tw.ctb

The following example will be helpful in cPanel or web servers.

find / -size +1000M : will list all the files above 1GB size.

find / -size +1000M > list

for i in `cat list`; do du -sch $i;done : will list all the files and their resoective size.

Create a disk partition on a disk greater than 2TB in size

Fdisk command does not supports partitioning of disk that has greater than 2 TB size. The parted tool supports GPT disk labels which can be used on disks larger than 2TB.
The example below demonstrates how to create a 6TB partition:

1. Use the parted tool to access the partition table of the device:

# parted /dev/sdj
Using /dev/sdj
Welcome to GNU Parted! Type ‘help’ to view a list of commands.


Once at the parted prompt, create a GPT label on the disk:

(parted) mklabel
Warning: The existing disk label on /dev/sdj will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
New disk label type?  [gpt]? gpt

Note: This will remove any existing partition table and partitions on the device.
3. Use the print command to show the size of the disk as reported by parted.  We need this later:

(parted) print

Model: Linux device-mapper (dm)
Disk /dev/sdj: 6000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

4. Create a primary partition on the device.  In this example, the partition will encompass the entire disk (using size from the step above):

(parted) mkpart primary 0 6000GB

5. Unlike fdisk, you do not have to write out the partition table changes with parted.  Display your new partition and quit.

(parted) print

Model: Linux device-mapper (dm)
Disk /dev/mapper/VolGroup00-gpttest: 6000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End          Size         File system  Name     Flags
1      17.4kB  6000GB  6000GB               primary

(parted) quit
Information: Don’t forget to update /etc/fstab, if necessary.


You can now create a filesystem on the device /dev/sdj1

7. Use mkfs.ext3 to make ext3 partition.

mkfs.ext3 /dev/sdj1

8. Use print option to displays the partition table.

parted /dev/sdj print

To check Disk Space Usage

Show files by size, biggest last:
ls -lSr

Show files in size, biggest first
ls -Ssh | head

Show top disk users in current dir.
du -s * | sort -k1,1rn | head

Show free space on mounted filesystems

df -h

Show free inodes on mounted filesystems

df -i

Show disks partitions sizes and types

fdisk -l

List all packages by installed size (Bytes) on rpm distros

rpm -q -a –qf ‘%10{SIZE}\t%{NAME}\n’ | sort -k1,1n

Calculate disk space in Plesk

When you remove files from plesk, in order to recalculate space, it doesn’t always update and shows the disk space usage correctly.

Running the following command from shell will correct the issue;

/usr/local/psa/admin/sbin/statistics –calculate-one –