4

I am having trouble with running out of diskspace of one of my clients servers.

The output of the commands ls -lah in /var/lib/mysql shows:

drwx------  2 mysql mysql  16K Dec 30  2015 database_xyz

But when I check the filesize in the same catalogue with the command du -sh *, the output shows:

22G     database_xyz

Why does the output of thoose commands shows two completely different results?

I have only 2.2GB left on the drive.

root@jon-cust-lifeincity:/var/lib/mysql# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg-root    49G   44G  2.2G  96% /
tmpfs                1007M     0 1007M   0% /lib/init/rw
udev                 1002M  108K 1002M   1% /dev
tmpfs                1007M     0 1007M   0% /dev/shm
/dev/sda1             228M   16M  200M   8% /boot

EDIT:

Turns out that database_xyz is in fact a catalogue, not a file. So the confusion was made up by my brain.

7

It seems that you have a misunderstanding about what you are being told. The ls -lah command lists the contents of the current directory. In this particular case that's /var/lib/mysql. Amongst other things you were told this

drwx------  2 mysql mysql  16K Dec 30  2015 database_xyz

You are misunderstanding what this is telling you.

You can consider a directory to be like a flat file containing a list of directory entries. (simply) A directory entry is a file name and a pointer to where that file resides on disk. This information takes up disk space.

What

drwx------  2 mysql mysql  16K Dec 30  2015 database_xyz

is telling you is that there is a directory entry in /var/lib/mysql called database.xyz. That entry is for a file type d which indicates it is a directory and amongst other things the size of the directory 'file' is 16K.

  • Yes,,, I just found out that the database_xyz is a directory, not a file... – Orphans Nov 9 '16 at 8:56
  • A directory is nothing more that a file with a listing of the files inside it. This directory listing file has thus a filesize. You can see the file by using vi database_xyz if the directoryname is database_xyz. – SPRBRN Nov 9 '16 at 17:41
  • @SPRBRN I don't think that's quite correct. I think vi recognises that it's a directory and treats it in a 'special' manner. Take a look at ext4.wiki.kernel.org/index.php/… and then try to 'cat' or more a directory file and see what happens. – Iain Nov 9 '16 at 20:51
2

To know the size of database_xyz file only just type

du -sh database_xyz

you will find the exact result

  • Yes,,, I just found out that the database_xyz is a directory, not a file... – Orphans Nov 9 '16 at 8:56
1

ls is not the right tool to find directory size. It works only for files not directories.

I can see that you are listing details of a directory (the first d char)

drwx------  2 mysql mysql  16K Dec 30  2015 database_xyz

Use du instead. This is a similar post at stackoverflow.

  • Yes,,, I just found out that the database_xyz is a directory, not a file... – Orphans Nov 9 '16 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.