Solved

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

Posted on 2011-03-03
29
3,105 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 21

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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

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 21

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 21

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 54

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
 
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 70

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 70

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 70

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 70

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 70

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 54

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 70

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

751 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