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,639
  • 10
  • 26
  • 36
Orphans
  • 1,404
  • 17
  • 26
  • 1
    Possible duplicate of [What is the difference between du -h and ls -lh?](http://serverfault.com/questions/290088/what-is-the-difference-between-du-h-and-ls-lh) – Handyman5 Nov 09 '16 at 10:16

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
  • 114,104
  • 20
  • 206
  • 289
  • Yes,,, I just found out that the database_xyz is a directory, not a file... – Orphans Nov 09 '16 at 08: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 09 '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 https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Directory_Entries and then try to 'cat' or more a directory file and see what happens. – user9517 Nov 09 '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

Sukhjinder Singh
  • 1,944
  • 2
  • 8
  • 17
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
  • 35,688
  • 8
  • 69
  • 98