Defragmentation process running via command prompt

Easily defrag your computer using a batch file

Opening a batch file as administrator

Defragmenting your computer can help improve its speed. Wondering how to easily defrag your computer by getting rid of the mouse clicks and simply opening a file? Below are the steps on how to do so.

Note: The solution below only works if you have administrative privileges or have access to the password of your computer’s administrator.

1. Open a text editor such as Notepad and type the following text:
defrag /c /h /u /v

Explanation:
/c will perform the defrag on all volumes
/h will run the operation at normal priority (default is low)
/u will print the progress of the operation on the screen
/v will print verbose output containing the fragmentation statistics

If you want to know more about other available options, open cmd.exe and enter the command defrag /?.

2. Save the file as a batch file by using an extension of .bat (instead of the default .txt). For example, save your file as _easily-defrag.bat.

Saving defrag code in a text editor as a batch file

3. Right click the saved file and choose “Run as administrator”.

Opening a batch file as administrator

4. Enter the administrator password and click OK.

5. Click “Yes” when prompted by Windows if you want “Windows Command Processor” to make changes to your computer. A terminal window then opens and runs the defragmentation process.

The batch file can now be reused anytime as long as you have administrative privileges. The defragmentation process is also much faster than when running the process from Windows Explorer (or File Explorer) because no graphical user interface is utilized.

Defragmentation process running via command prompt

Pinoy Geekster is a web developer, contributor to various sites online, loves everything about computers, and a big fan of chicken and egg dishes.

2+
Share this page

Leave a Reply