Solved

How to find Folder Free space in MB or GB using DOS /Unix command?

Posted on 2011-03-03
29
2,765 Views
Last Modified: 2012-08-14
In my client place they have many servers and each server has many folders. I need to find all the folders in the server free space size in MB/GB. Please let me know how to find using Dos command or Unix command. I used DIR command  but it gives many information which are not requied for me. Thanks for the help
0
Comment
Question by:PKTG
  • 6
  • 5
  • 5
  • +5
29 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35031753
Try

du -h

and

df -h

wmp
0
 
LVL 14

Expert Comment

by:theras2000
ID: 35031763
how about if you just type:
dir | find "free"
0
 
LVL 20

Expert Comment

by:tfewster
ID: 35039135
In Unix, `df` (display filesystems) shows total/used/available space in each filesystem (equivalent to a DOS "drive letter"), usually in kilobytes

If your version of Unix supports it, `df -h` shows "friendly" units, i.e. Mb & Gb
0
 

Author Comment

by:PKTG
ID: 35201646
Thanks for the info. We don't have Unix Tools in Soem of our production Machine.  So for me dir | find "free"  command helped lot. But still it is showing in byres. Is there any way i can get the files zie in GB using Dir command. Thanks again
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35201745
The only thing I'm aware of is the "/C" switch of "dir" - "Include thousand separator in file sizes".

Maybe it could make the output a bit more eye-friendly.
0
 

Author Comment

by:PKTG
ID: 35202185
can you please give one example? Thanks.
0
 
LVL 4

Expert Comment

by:aavictor
ID: 35344483
Wait!  What's free space of folder?  Or you mean a free space of HDD or partition? Or
the free space of file quota in win 2003 or early? Or free space in Win 2008 file quota?
For Win 2008 server, you can set folder quota for user (as I remember its feature)
For Win 2003 server, the free space is only file quota max - space for file stored by owner.
0
 

Author Comment

by:PKTG
ID: 35444843
We have 4 servers in Cluster and Each server has 5 drives. Each drive has 1TB total space. I want to know how much free space(in GB) avaialble in each drive in all the 4 servers.
0
 
LVL 20

Expert Comment

by:tfewster
ID: 35450961
The answer is, "it depends". You have 20TB of physical disk, but possibly as little as 12TB of usable space. And if the data is replicated across all servers, 1TB of data will use 4TB of that theoretical usable space.

What operating systems, clustering mechanism and RAID setup do you have?
0
 

Author Comment

by:PKTG
ID: 35493713
OP: Windows 2008 R2, it is IBM XIV drives. I don't know more details. My responsibility is giving free space details to managemnet . Thanks.
0
 
LVL 20

Expert Comment

by:tfewster
ID: 35495368
That's me out then, 'cos I'm like the maid - I don't do Windows ;-)

You might be better linking this to the Windows Server topic areas. I'm pretty sure the command line won't be able to show you RAID or clustering setups
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 35868102
==> I need to find all the folders in the server free space size in MB/GB.

Can you clarify that, folders don't have free space, only logical drives in Windows.

~bp
0
Do email signature updates give you a headache?

Constantly trying to correctly format email signatures? Spending all of your time at every user’s desk to make updates? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today!

 
LVL 38

Expert Comment

by:wesly_chen
ID: 35868432
Here you are
http://en.kioskea.net/forum/affich-42442-dos-command-batch-file-to-find-a-folder-size

The one I verified and modified as following
--- dir_size.bat --
@echo off
setLocal EnableDelayedExpansion
set /a value=0
set /a sum=0
FOR /R %1 %%I IN (*) DO (
set /a value=%%~zI/1048576
set /a sum=!sum!+!value!
)
@echo Size is: !sum! Mb
--------
Then run
dir_size.bat c:\sample
Size is : 9161 Mb

If the dir size is less the 1 MB, then it show 0 MB.

You can change this line
set /a value=%%~zI/1048576   ===> report in MB
to
set /a value=%%~zI/1073741824     ===> report in GB
or
set /a value=%%~zI/1048576   ===> report in KB

Also change the last line
@echo Size is: !sum! Mb    ===> to reflect the unit
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 35868441
woo typo, should be
set /a value=%%~zI/1024   ===> report in KB
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 250 total points
ID: 35869441
In Cluster mode, do your 4 drives not have the same setup for all machines?

Whatsoever, for a single machine:
@echo off
setlocal EnableDelayedExpansion
set log=%1
if "%1" == "" set log=%~dpn1.txt
for /F "tokens=2-6 delims=:\ " %%A in ('fsutil fsinfo drives') do (
  for %%d in (%%A %%B %%C %%D %%E) do (
    for /F "tokens=2 delims=:" %%f in ('fsutil volume diskfree %%d: ^| find "of free bytes" ') do @(
      set mb=%%f
      set mb=!mb:~,-3!
      set /A mb /= 1024 >nul
      echo %computername% %%d: !mb!
    )
  )
) >> "%log%"

Open in new window

That works for up to 2 TB free per drive.
You can apply this script to several machines e.g. by using the free psexec utility from www.sysinternals.com:
   psexec @machines.txt -u domain\user -p pwd \\server\share\pathToTheBatch\BatchFile.cmd
Data will be appended (!) to the file located and named like the batch (but with .txt extension). For using a different location, just change the batch file or supply the new path and name after the batch file call in psexec.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 36110315
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 

Author Comment

by:PKTG
ID: 36050733
Hello wesly_chen,
I typed the batch file in command prompt and got the result only "Size is: !sum! k". pls see the attachment. pls correct me what i am doing wrong. Even i put this in .bat file stll it did't return anything.


batchfile.JPG
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 36050767
PKTG,

If you want to continue with the question, you need to post a comment, pressing OBJECT instead of SUBMIT. That stops the process I, as Cleanup Volunteer, have initiated.

Did you try my suggestion, too? Both the code snippets from me and wesly_chen need to be put into a .cmd or .bat file.
Please be aware that wesly_chen's suggestion only shows how much space is occupied, not free.
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36051210
Please open the "notepad.exe" and copy and paste my code into it.
Save it as c:\dir_size.bat.
Then run
c:\dir_size.bat "Windows"
  where "Windows" is the directory/folder name.

Yes, my script is calculating the size of directory/folder, not disk free space.
@echo off
setLocal EnableDelayedExpansion
set /a value=0
set /a sum=0
FOR /R %1 %%I IN (*) DO (
set /a value=%%~zI/1024
set /a sum=!sum!+!value!
)
@echo Size is: !sum! Kb

Open in new window

0
 
LVL 68

Expert Comment

by:Qlemo
ID: 36051316
wesly, did you read my last comment? And then the question again?
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36051369
@Qlemo
I have read your comment so I said "my script is calculating the size of directory/folder, not disk free space." as in my last comment.
Besides, I tested your script in my Windows 7 laptop and it doesn't work for me.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 36051424
Sorry for that "have you read" stuff - I did not read, obviously.

Regarding my script: Tested on both Vista x32 and W7 x64, and it works for me. The only effect maybe occuring is that part of the script are echoed to the file in addition, which can be resolved by replacing each
  do (
with
 do @(

What does not work for you exactly?
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36051508
OK.
I appended the following line at the bottom of your code
---
type %log%
----
To display the result on screen.

What is line 4, "set log=%~dpn1.txt" do?
For some reason, if I did not specify the file name, say
c:\temp\BatchFile.cmd
It generates ".txt" file. Which is kind of odd.

If I run
c:\temp\BatchFile.cmd DiskFree.txt
then it generates "DiskFree.txt" file.
Which is good.
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 36051670
Not sure if it will be of any use, but I worked on a solution in a related question a while back...

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Q_26608584.html

~bp
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 36052951
Oi. Line 4 of my batch is wrong. It needs to sound
  if "%1" == "" set log=%~dpn0.txt
That line is the only one I changed when testing, so it always worked for me as expected ...

%~1 will take the first parameter given, and remove surrounding quotes, if any.
%~0 does the same for the batch file name.
%~dpn0.txt generates the file name from the drive, path, and filename (no extension) of the batch file, and appends .txt extension.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now