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.

chicks
  • 3,915
  • 10
  • 29
  • 37
Orphans
  • 1,474

3 Answers3

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.

user9517
  • 117,122
2

To know the size of database_xyz file only just type

du -sh database_xyz

you will find the exact result

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.

Khaled
  • 37,789