Identify sparse files using linux commands

Below strings may help you to identify “what are sparse files and how to identify sparse files ?”

You would have experienced a sparse file creation question ( something like “ Allocate entire disk now” ?)at the time of virtual machine creation. So it is basically creating a sparse file behind the scenes.

A sparse file is a file with empty space or “holes”, which are not actually stored on disk. In the future you can use these “holes” for allocating data blocks.

If the “holes” are filled with “zeros” for some area which can turned out to be a sparse file .

So, how to identify a sparse file?

You can use either “du -sh ” or “ls -s to reveal a sparse file.

I have a sparse file created in name of “big_image”

[terminal]
[root@humble-node ~]# du -sh bigimage
0 bigimage
[root@humble-node ~]# ls -lh bigimage
-rw-r–r–. 1 root root 4.0G 2010-02-20 17:19 bigimage
[root@humble-node ~]# du -sh bigimage
0 bigimage
[root@humble-node ~]# ls -s bigimage
0 bigimage
[root@humble-node ~]#
[/terminal]

Ref#man cp in a linux system to play some more with sparse file and cp process..

I received a SIGKILL here 🙂