- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sub-directory size
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-27-2005 06:26 AM
тАО06-27-2005 06:26 AM
What is command or script to find sub-directory or directory size in MegaByte (MB) or GB ?
Thanks in advance.
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-27-2005 06:30 AM
тАО06-27-2005 06:30 AM
Re: sub-directory size
This will give you the size in Kb. Multiply this by 1024 for Mb.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-27-2005 06:36 AM
тАО06-27-2005 06:36 AM
Re: sub-directory size
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-27-2005 06:43 AM
тАО06-27-2005 06:43 AM
SolutionIf you multiplied the output by 1024, you'd get the size in BYTES.
Size in KB
# du -ks /somedir
1234567890 somedir
Size in MB
# echo 1234567890/1024|bc -l
1205632.70507812500000000000
Size in GB
# echo 1205632.705078125/1024|bc -l
1177.37568855285644531250
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-27-2005 05:08 PM
тАО06-27-2005 05:08 PM
Re: sub-directory size
Size in KB
echo `du -ks
Size in MB
echo `du -ks
Size in GB
echo `du -ks
Regards
Ganesha Sridhara
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-27-2005 06:48 PM
тАО06-27-2005 06:48 PM
Re: sub-directory size
See this attached script, found on this forum. Look like that :
/# dumegs *
bin 0 Kb
cdrom 0 Kb
dev 104 Kb
etc 48,712 Mb
gv0 118,830 Mb
gv1 3,461 Gb
home 592 Kb
lib 0 Kb
log 1 Kb
lost+found 0 Kb
net 0 Kb
opt 1,709 Gb
root 4,608 Mb
sbin 36,728 Mb
stand 40,968 Mb
tmp 27 Kb
tmp_mnt 0 Kb
usr 1,174 Gb
var 728,632 Mb
Joel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-28-2005 12:04 AM
тАО06-28-2005 12:04 AM
Re: sub-directory size
We have to devide by 1024 to get size in MB
Regards
Mahesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-28-2005 05:03 AM
тАО06-28-2005 05:03 AM
Re: sub-directory size
#!/usr/bin/ksh
# du in Kbytes, Mbytes, Gbytes
# ============================
# usage dumegs [-p directory] [directories]
# option : -p directory : percent of this parent directory
# other parameter : directories to display
# fonction du -s
du_it()
{
typeset -R10 vsize
typeset -R3 vpc
bytes=`du -s $1 | cut -f1`
if (( ${#1} < 8 )) ; then
ztab="\t\t\t"
elif (( ${#1} < 16 )) ; then
ztab="\t\t"
else
ztab="\t"
fi
if [ $bytes -le 999999 ] ; then
bytes=`expr $bytes \* 512`
kbytes=`expr $bytes \/ 1024`
else
kbytes=`expr $bytes \/ 2`
fi
if [ $kbytes -gt 999 ] ; then
mbytes=`expr $kbytes \/ 1024`
xbytes=`expr $mbytes \* 1024`
dbytes=`expr $kbytes - $xbytes`
if [ $dbytes -le 10 ] ; then
dbytes="00$dbytes"
fi
if [ $dbytes -le 100 ] ; then
dbytes="0$dbytes"
fi
if [ $mbytes -gt 999 ] ; then
gbytes=`expr $mbytes \/ 1024`
xbytes=`expr $gbytes \* 1024`
dbytes=`expr $mbytes - $xbytes`
if [ $dbytes -le 10 ] ; then
dbytes="00$dbytes"
fi
if [ $dbytes -le 100 ] ; then
dbytes="0$dbytes"
fi
vsize=$gbytes,$dbytes
unit=" Gb"
else
vsize=$mbytes,$dbytes
unit=" Mb"
fi
else
vsize=$kbytes
unit=" Kb"
fi
if [ -n "$optp" ] ; then
if [ -n "$tkb" ] ; then
vpc=$(expr $kbytes \* 100 \/ $tkb)
pc=" $vpc %"
else
pc=" (parent directory)"
fi
fi
echo "$1$ztab$vsize$unit$pc"
}
# main dumegs
tkb=
optp=
optparg=
while getopts :p: OPT "$@"
do
case $OPT in
p) optp=1 ; optparg=$OPTARG ;;
\?) echo "usage dumegs [-p directory] [directories]" ; exit 1 ;;
esac
done
if [ -n "$optp" ] ; then
if [ -z "$optparg" ] ; then
echo "option -p : missing directory parameter"
exit 2
fi
du_it $optparg
tkb=$kbytes
shift 2
fi
if [ $# -gt 0 ] ; then
for dirs in $*
do
if [ -d "$dirs" ] ; then
du_it $dirs
elif [ -f "$dirs" ] ; then
du_it $dirs
fi
done
else
du_it $PWD
fi
$