Disk usage with links pointing to files on same FS


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Disk usage with links pointing to files on same FS
# 1  
Old 01-28-2014
Reference Disk usage with links pointing to files on same FS

I want count size of all directories on my current File System including size of links only if the target of these links is on same filesystem.

I tried below but it gives size of link target even if its on a different FS:
Code:
du -skL *

also the -x option did not help.
Any help.

Last edited by Franklin52; 01-28-2014 at 10:10 AM.. Reason: Please use code tags
# 2  
Old 01-28-2014
You may have to do this the slow way. So.. you could do your original command and the a second command finding the links only (e.g. using find) that go off filesystem and subtracting that out (find might not do it though).

You may be able to do it one pass using find and/or looping, but it will be slow.
# 3  
Old 01-29-2014
When you say "all" directories, do you want to descend the top level directories from your current position and report them too? If so, leave off the -s flag. It may be useful to pipe this into a sort as below:-
Code:
du -kx | sort -n

You can choose if you want to include the -L flag. I think that links to files will just count the link where links to a directory will count the content of the directory. Of course, you are not considering hard links within your filesystem, however in my testing, I have found that if I have:-
Code:
robin @ /tmp/robin>ls -l
total 8
drwxr-xr-x 2 robin robingrp 4096 Jan 29 10:18 1
drwxr-xr-x 2 robin robingrp 4096 Jan 29 10:19 2
lrwxrwxrwx 1 robin robingrp    1 Jan 29 10:19 3 -> 2
robin @ /tmp/robin>ls -li 1 2
1:
total 183340
528470 -rw-r--r-- 2 robin robingrp 187740160 Jan 29 10:18 bigfile

2:
total 183340
528470 -rw-r--r-- 2 robin robingrp 187740160 Jan 29 10:18 bigfile
robin @ /tmp/robin>

..... you can see that directories 1 & 2 contain the same file hard linked (same inode number) and directory 3 is symbolically linked.

I then get this output:-
Code:
robin @ /tmp/robin>du -k
183344  ./2
4       ./1
183352  .
robin @ /tmp/robin>

..... so the file is only reported once. i must admit I don't know why it is reported under directory 2 rather than 1, but it's something to be aware of.
You can also see that 3 doesn't list at all.

This is on RHEL6, but other operating systems may vary. It might be that it reports the space used under 1 as the same as 2, but the total doesn't match up.

I hope that this helps.


Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Disk usage monitoring and record the disk used in last 24 hour

HI I am Trying to edit the below code to send email every day with difference of disk utilized in for last 24 hours but instead getting same usage everyday. can you please help me to point out where my calculation is going wrong. Thank you. ================= #!/bin/bash TODAY="at $(date... (0 Replies)
Discussion started by: Mi4304
0 Replies

2. UNIX for Advanced & Expert Users

Comparing two files and writing mismatched rows along with mismatched columns. Pointing out the mism

I got a requirement where I need to compare two files wrt to each columns and write the corresponding difference in another file along with some identification showing mismatched columns. Pointing out the mismatched columns is my main problem statement. For example we have files like: File 1 ... (8 Replies)
Discussion started by: piyush pankaj
8 Replies

3. Shell Programming and Scripting

Perl Script to find the disk usage and to delete the files which is consuming more space

Hi All, I have written a script to check the file system usage and to delete the files which is consuming more space.Please check whether the script is corrcet #Script Starts here #!/usr/local/bin/perl #Program to find the disk space and to delete the older files #Checks the type of OS... (8 Replies)
Discussion started by: arunkarthick
8 Replies

4. Red Hat

Disk usage showing 100% after deleting files also | Red Hat Linux 3.2.2-5

My Redhat Linux system is always showing 100& disk usage. I have removed almost all the files, but no use and I am always getting 100% disk usage.!! Filesystem 1K-blocks Used Available Use% Mounted on /dev/hda2 36337384 36066352 0 100% / I can... (7 Replies)
Discussion started by: sanoop
7 Replies

5. UNIX for Dummies Questions & Answers

du - Disk Usage for only files and NOT directories.

Hello, Could any one help me how to find the Disk Usage for all the files in the running directory and the sub directories without the disk usage of the directory. I mean to say, i need only the file names without the size of the directories. See, i used this command du -a .|sort... (3 Replies)
Discussion started by: RRVARMA
3 Replies

6. UNIX for Dummies Questions & Answers

How to trace the big files causing high disk usage

Hi All, One very urgent issue and I need your help. I have two V490 servers installed with Sun Solaris 10. I have traced out that the disk usage is running out of space for both the servers. Currently the /dev/md/dsk/d10 device is 91% in one server and another is 56% and it is increasing... (1 Reply)
Discussion started by: ailnilanjan
1 Replies

7. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

8. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

9. UNIX for Dummies Questions & Answers

disk usage

how to i find out the disk usage on a server. say in windows examples its like C:/ D:/ and checking out the disk space. how can i find in Unix. can i just use df -k or should i go to each volume group and find that way. plz respond (2 Replies)
Discussion started by: karthikosu
2 Replies

10. Filesystems, Disks and Memory

Pointing one hard drive name to another disk

Pointing one hard drive name to another disk -------------------------------------------------------------------------------- I have 2 disk drives - s2d9 & s2d11 on a solaris Unix system It was mapped so that anything that tried to call s2d9 would be pointed to s2d11 since s2d9 was bad.... (2 Replies)
Discussion started by: andy57s
2 Replies
Login or Register to Ask a Question