Showing posts with label du. Show all posts
Showing posts with label du. Show all posts

Friday, July 16, 2010

Create huge files fast with dd

Here is a quick way to create very large empty files without writing every byte using dd.

# dd if=/dev/zero of=largeemptyfile.img bs=1M count=1 seek=16999
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.001772 seconds, 592 MB/s
# ls -lh
total 1.1M
-rw-r--r-- 1 root root 17G Jul 16 09:07 largeemptyfile.img
# du -h
1.1M    .

Notice that the actual file is only 1.1 MB, but the file shows as 17GB.  This is because dd basically wrote the first and last parts of the file, and left the middle alone.  You can now use this file for anything, such as a Xen disk image.  Once it is in use, it will report as the full 17GB with du.

Thursday, June 4, 2009

Quicky find what directories are using up space on your disk

The df -h command will tell you disk usage from a mountpoint perspective, but the command du tells you from a directory perspective. Use the command:

du -h / --max-depth=1

To show disk usage for each individual directory on the system, or go lower down to see usage on a particular directory:

du -h /var/log --max-depth=1

Wednesday, October 1, 2008

List largest (or smallest) files

If you want to find the largest files in a directory which are consuming precious space, you can use the following command:

openSuSEServer:~ # du -kh /var | sort -n | tail

then, to sort the smallest files, use the inverse command:

openSuSEServer:~ # du -kh /var | sort -n | head