LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-30-2004, 05:02 PM   #1
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Rep: Reputation: 15
Help with file size script


At my university we have a disk space quota, so I used to just run du -sh * to see what was taking up space, but the problem was that hidden folders would not show up. To solve this I created a simple script to do it for all folders. My problem is that my script will not work on folders with spaces in the name. Can any some look it over and suggest a solution?

for file in `ls -a`
do
if [ $file != "." -a $file != ".." ]; then
du -s $file
fi
#du -s $file
done
 
Old 03-30-2004, 05:09 PM   #2
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
quick way, at the start change IFS variable to a newline exclusively

IFS="
"
 
Old 03-30-2004, 05:11 PM   #3
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Original Poster
Rep: Reputation: 15
Wow, that was easy.

Thanks
 
Old 03-30-2004, 06:33 PM   #4
kooch
Member
 
Registered: Mar 2004
Location: Upstate NY
Distribution: Slackware/YDL
Posts: 77

Rep: Reputation: 15
/* nevermind */
 
Old 03-31-2004, 03:47 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
what about?

Code:
du -sh * .*
 
Old 03-31-2004, 03:48 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
thats supposed to be

du -sh .* *

looks like DOS *.*
 
Old 03-31-2004, 11:50 AM   #7
mgatny
Member
 
Registered: Mar 2004
Posts: 41

Rep: Reputation: 15
Another way:

find -exec du -hs {} \;
 
Old 03-31-2004, 03:49 PM   #8
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
That last one prints every single file. Bit of an overkill IMHO. For me the idea of "du" is to see a short list of the amount of data in the subdirs.

I use this in a script called "dusort" to produce a list of subdirs of the working dir sorted by size.
Code:
du -s * | sort -g | cut -f 2 | xargs du -hs
 
Old 03-31-2004, 04:22 PM   #9
jpc82
Member
 
Registered: Oct 2001
Distribution: Gentoo
Posts: 140

Original Poster
Rep: Reputation: 15
the problem with du -sh .* * is that it will also evaluate ..
 
Old 03-31-2004, 05:41 PM   #10
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
you can use '-type d' to find only directories:
Code:
find . -type d -exec du -sh {} \;
 
Old 04-01-2004, 04:55 AM   #11
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
True, that's better.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Script to delete files with 0k file size in a directory justgiver Linux - Newbie 4 01-28-2008 04:56 AM
File Size Shell Script BlackLabel Programming 7 11-27-2007 07:48 PM
when creating a *.iso file, how to make the file size smaller? minm Linux - Newbie 8 12-26-2004 09:58 PM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 04:18 PM
Need script to check file size. _TK_ Linux - General 1 08-06-2001 08:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:39 PM.

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