Tips Tricks Tutorials

WEB-NES-BAY

Learn Tips and tricks on Linux, Hacking, linux, PHP, Perl, Web, Hardware

bookmark bookmark
WEBNESBAY On September - 6 - 2009

Turns out that both commands, the report differently on the disk space used and to demonstrate this and understand it in better shape, we’ll see with an example, together with another friend the command. If we use the du command, as follows:

# du -sh /

el-sh means we want the grand total (s: summarize), and use points to define the size, MB, GB, etc..

obtain the following result:

13G /

Then using the df command, ostensibly to perform the same calculation, we may use the following:

df -h /

el-h mean we want to use points to define the size, MB, GB, etc..

for what we would get a result like this:

Filesystem Size Used Avail Use% Mounted on
/dev/sda3   64G  30G   32G  49% /

According to du we used in our drive 13G and df tells us that we are using 30GB! then wonder where the 17GB that are not in the recorded. Well it turns out that the “open file descriptor” is the cause of this difference in results, since the df takes into account the open files and du make their calculations on the files stored in each of the folders recursively.

Now where the “lsof” comes into play to help us know what happens with this growth in disk space used. When you run the command as follows:

lsof -R | more

We get a result like this:

COMMAND PID PPID USER FD TYPE DEVICE SIZE NODE NAME
init 1 0 root cwd DIR 8,3 4096 2 /
init 1 0 root rtd DIR 8,3 4096 2 /
init 1 0 root txt REG 8,3 32652 7028751 /sbin/init
init 1 0 root mem REG 0,0 0 [heap] (stat: No such file or directory)
init 1 0 root mem REG 8,3 9592 7260587 /lib/tls/i686/cmov/libdl-2.3.6.so
init 1 0 root mem REG 8,3 1241392 7260584 /lib/tls/i686/cmov/libc-2.3.6.so
init 1 0 root mem REG 8,3 79368 7258210 /lib/libselinux.so.1
init 1 0 root mem REG 8,3 219824 7258211 /lib/libsepol.so.1
init 1 0 root mem REG 8,3 88164 7258114 /lib/ld-2.3.6.s

I used the “-R” so I will list the parent process and identify who is using those files. Therefore allow us a better way to detect such growth “ghost”.

As a practical example could do the following.

First we use the following commands to the / home:

# df -h /home

# du -s -h /tmp

Now create a BIG archive:

# cd /home/user
# cat /bin/* >> demo.txt
# cat /sbin/* >> demo.txt

We joined another console demo.txt open the file using the vi text editor:

# vi /home/user/demo.txt

without closing vi (hold it running on that console), go back to the first console and delete the file demo.txt

# rm demo.txt

Now run du and df and note the difference.

# df -h /home
# du -s -h /tmp

Return to the next console and close vi without saving the file and the apparent cause of the problem seems to have been resolved, and the output of du and df commands may already be correct. This example was just to “replicate” these circumstances in a test environment as in the production environment, these differences can easily be given by means of the services are running, so I included the “lsof” and that can help us detect the culprit of disk growth could reach a “saturated”. Well, this was my first post to tipsdeaweb.com, I hope to return soon with some of those tips that we would find it more easily and probably.

Related posts:

  1. How to repair windows using linux
  2. Get SSH back door in linux
  3. Control Apache with the apachectl command
  4. Chat with Friends through ms dos Command Prompt
  5. How to setup a DNS server with bind in Ubuntu linux
  6. Prevent end-user to restart your linux computer
  7. DVD Playback in Linux
  8. Download youtube videos in ubuntu linux
  9. How to block websites in Ubuntu Linux
  10. Hack WEP Key in Ubuntu Linux
Categories: Linux

Leave a Reply