![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help Required: Command to find IP address and command executed of a user | loggedout | Security | 2 | 08-06-2008 05:12 PM |
| how to? launch command with string of command line options | TinCanFury | Shell Programming and Scripting | 5 | 04-28-2008 03:06 PM |
| inconsistent ls command display at the command prompt & running as a cron job | rajranibl | Linux | 5 | 07-30-2007 05:26 AM |
| How to use more than one MPE command STREAM with Unix command in a single shell? | bosskr | HP-UX | 1 | 10-16-2006 01:16 PM |
| How to use more than one MPE command STREAM with Unix command in a single shell? | bosskr | Shell Programming and Scripting | 0 | 09-19-2006 06:44 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi all i am trying to list contents of a directory in summarised user readable form from file size highest to lowest?
I have used du -k * | sort -rn however this provides the output in KB if i use du -sh * this lists the contents but does not list in appropriate order e.g. some of the files in MB are listed below KB ones etc. I'm really struggling with this one and wondered if there are any experts who could help? I'm not bothered if they are listed ascending or descending as long as GB are above MB and MB are above KB Thanks, pure_jax |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
du -k uses a block size of 1k, so that's why it only produces the output in KB.
Try Code:
du -h | sort -rn |
|
#3
|
|||
|
|||
|
As a starting, adjust to your needs. This can done more efficient, but it's done like this so you can see the concept.
Code:
du -sk * | sort -rn | \
while read SIZE ENTRY
do
# if size > 1048576 then it is at least 1 GB big
if [ ${SIZE} -gt 1048576 ]
then
NEWSIZE=`echo "${SIZE}000 / 1048576" | bc | sed -e "s/\(...\)$/\.\1/"`
printf "% 10s %s\n" ${NEWSIZE}G $ENTRY
# if size > 1024 then it is at least 1 MB big
elif [ ${SIZE} -gt 1024 ]
then
NEWSIZE=`echo "${SIZE}000 / 1024" | bc | sed -e "s/\(...\)$/\.\1/"`
printf "% 10s %s\n" ${NEWSIZE}M $ENTRY
else
printf "% 10s %s\n" ${SIZE}K $ENTRY
fi
done
|
|
#4
|
|||
|
|||
|
Many thanks sb008
Worked a charm :-) |
|||
| Google The UNIX and Linux Forums |