Hello!This time, I will introduce a one-line command to adjust the free space of the hard disk to the specified size!
Adjusting the free space is one of the operations that you don't usually do.Even though it is an adjustmentUnfortunately you can't free up space with this command.. OnlyReduce and adjustdoing.
It is a well-established theory that the more free space you have in normal use, the better.It is not recommended to use the capacity unnecessarily.
However, for those who work on personal computers, I think that there are occasional situations where you want to test something or intentionally arrange the capacity.
This time, in such a caseAdjust the free space to the specified sizeI would like to introduce the command.
Thing you want to do
Easily reduce the storage capacity to the specified size with a command.
#Powershell fsutil file createnew c:\dummy.dat ((Get-PSDrive C).free - 15gb) rem コマンドプロンプト @powershell -command "fsutil file createnew c:\dummy.dat ((Get-PSDrive C).free - 15gb)"
When you execute this command, a file called "dummy.dat" will be created directly under the C drive, and the free disk space will be the specified size (15GB). The contents of "dummy.dat" are meaningless data.
* Fsutil is supported on Windows 7 or later.
Creating a dummy file using fsutil
fsutil is a program used to operate the file system, and this time I used a command to create a dummy file that does not mean "fsutil file create new".
fsutil file createnew [file path] [file size]
For the file path, specify the file path and file name of the location you want to create.For the file size, specify the file size in bytes.
For example, if you want to create "File.dat" of "10MB" in "directly under D drive",
fsutil file createnew D: \ File.dat 10485760
You can create it with a command like this.
* By the way, you cannot specify something like "○○ GB" with the command prompt alone.Use the calculated value. 10MB = 10x1024x1024 = 10,485,760
Get disk space with Powershell command and decide the adjustment amount
Powershell provides a command called "Get-PSDrive" to get disk information.
By specifying the drive letter, we will go to get the information of that drive.
There is a value (: property) called "free" in it, which contains the free disk space.
(Get-PSDrive [drive letter]). free
The adjusted free space is calculated by subtracting the specified size from the total free space.
Well, it's natural because the file will be created by subtracting from the free space.
(Get-PSDrive [Drive Letter]). Free-[Adjusted Disk Capacity]
This time I set it to 15GB, but of course other values are OK. I tried to specify in "GB" units, but you can also specify in [MB], [KB], etc.
Size specification with unit
This is kind of a bonus, but the command prompt (black console) doesn't support units of data.Therefore, to express "1MB", you have to express "1048576". (1x1024x1024)
Since Powershell (blue console) supports data units from the beginning, you can also specify the size with [GB], [MB], [KB], etc.
This time, I introduced the command to adjust the free space to any size.
To restore the adjusted size, use the created dummy file.Delete completelyIt will be resurrected.
It seems that there are many people who just move it to the trash can, so please be careful.
I don't think there are many situations where you have to adjust the free space, but in my case I used it to check the behavior of the OS and hard disk.
As with the design of the OS, in order to understand the operation of the purchased computer and the software to be installed."What happens when the free space is extremely low?"Often led to trouble without knowing.
This could (rarely) cause system corruption, such as when you had to install a program that consumes a lot of memory.
It is also very useful for conducting such tests, so please use it if you like.
I hope it helps you.