LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-04-2015, 10:55 AM   #1
sburnay
LQ Newbie
 
Registered: Sep 2011
Location: Lisbon, Portugal
Distribution: Ubuntu, CentOS & SUSE
Posts: 29

Rep: Reputation: Disabled
du and fd commands give contradictory outputs


Hey!

I have an Ubuntu Server 12.04 LTS (64bit version),

My filesystem is organized in partitions and one of them is used for logging purposes (/dev/sdb mounted on /var/log).

Somehow when I run df I get information that my log partition is at 100 of its 7GB capacity and by running du I find it is only using a few hundred kB, it makes no sense.

Even when I'm just listing the /var/log content with 'ls -lh' I do not find many files:
Code:
root@MYSERVER:/# sudo du --max-depth=1 -x -h /var/log/
4.0K    /var/log/news
12K     /var/log/mysql
76K     /var/log/apache2
16K     /var/log/lost+found
4.0K    /var/log/sysstat
4.0K    /var/log/apt
4.0K    /var/log/landscape
816K    /var/log/
root@MYSERVER:/# df -h | grep log
Filesystem                        Size  Used Avail Use Mounted on
/dev/sdb                          7.0G  6.7G   24M 100% /var/log
Thank you in advance for your help

Last edited by sburnay; 12-04-2015 at 11:34 AM.
 
Old 12-04-2015, 11:51 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,138

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
du only lists files which are in directories. Anonymous files are not listed. For example if a program has a file open which has been unlinked from any directory then it will not be counted.
 
Old 12-04-2015, 03:37 PM   #3
sburnay
LQ Newbie
 
Registered: Sep 2011
Location: Lisbon, Portugal
Distribution: Ubuntu, CentOS & SUSE
Posts: 29

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by smallpond View Post
du only lists files which are in directories. Anonymous files are not listed. For example if a program has a file open which has been unlinked from any directory then it will not be counted.
But I also tried 'ls -lh' and didn't find any big files nor a large collection of smaller files.

I really don't know what is taking so much space in my /var/log partition and I'm afraid it might affect the server's performance.

I even tried a reboot to see weather it would make a difference, but it remained the same
 
Old 12-04-2015, 05:22 PM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
I notice you used the "-x" (--one-file-system) option in your du command. Is there actually anything mounted anywhere under /var/log ? That seems unusual, bit if so, you could have files hidden under that active mount point. If not, then "fsck -f /dev/sdb" would be in order.
 
Old 12-07-2015, 04:49 AM   #5
sburnay
LQ Newbie
 
Registered: Sep 2011
Location: Lisbon, Portugal
Distribution: Ubuntu, CentOS & SUSE
Posts: 29

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
I notice you used the "-x" (--one-file-system) option in your du command. Is there actually anything mounted anywhere under /var/log ? That seems unusual, bit if so, you could have files hidden under that active mount point. If not, then "fsck -f /dev/sdb" would be in order.
Hey!

Thanks for your advice, but I have no mount points within /var/log.

How can I check for hidden files?

I've tried "fsck -f /dev/sdb" and it identified/corrected a few issues:
  • several "Free blocks count wrong (98036, counted=1769110)"
  • Orphaned inodes

The result from fsck:
Code:
/dev/sdb: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdb: 44/458752 files (11.4 non-contiguous), 65898/1835008 blocks
The partition remains accusing 100

Yet, after another reboot, it went to 4% used which is the correct value

Last edited by sburnay; 12-07-2015 at 05:29 AM.
 
Old 12-07-2015, 06:50 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Quote:
Yet, after another reboot, it went to 4 used which is the correct value
This is because when a file is 'deleted' (aka unlinked), the entry disappears from the inode (dir), but the storage is only returned to the system when ALL processes that have it open have relinquished the file. If any process has the file open, it will continue to take up space.

df 'sees' the file space usage as still there, du doesn't.

Its a very common qn/soln and you'll see a lot of hits on google for it.
You can easily test it yourself by writing a small prog that writes to a test file and the 'delete' the file manually from another terminal.

Last edited by chrism01; 12-07-2015 at 06:51 PM.
 
Old 12-08-2015, 12:06 AM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,780

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Code:
lsof /var/log
shows the processes that have files opened there - in some cases even shows the "deleted" files.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to convert unformatted binary files/outputs to netcdf outputs in linux? sarasari Programming 2 03-11-2014 11:30 PM
what is the command to store a list of commands and their outputs in a file ursuniel Linux - Newbie 9 01-30-2014 03:29 PM
Why does cygwin and linux give different array outputs? carlr Programming 6 08-08-2012 05:31 PM
i need to store the outputs of 2 commands in 2 variables and compare the two variable anurupr Linux - Newbie 10 03-04-2010 05:05 AM
c++ uses system to give commands to bash darkRoom Programming 2 03-10-2005 04:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration