The UltraDefrag installer places the command line tool udefrag.exe into the System32 directory. Therefore it may be run without specifying the full path. View screenshots...
Command line options
Usage:
udefrag [command] [options] [driveletter:] [path(s)]
Commands:
- -a, –analyze
- Analyze the disk.
- –defragment
- Defragment the disk. This is the default action.
- –optimize-mft
- Optimize the MFT by placing its fragments as close to each other as possible. This is also included in full and quick optimization.
- -q, –quick-optimize
- Optimize the disk space by moving not fragmented files to the beginning of the disk.
- -o, –optimize
- Optimize the disk space by moving all files to the beginning of the disk.
- -l, –list-available-volumes
- List all disks available for defragmentation, except removable. Each line of the output contains a drive letter, filesystem name, total space and amount of free space.
- -la, –list-available-volumes=all
- List all disks available for defragmentation, including removable.
- -h, -?, –help
- Show help screen. Running UltraDefrag without arguments has the same effect.
- Note
- The commands are exclusive and can't be combined with each other.
Options:
- -r, –repeat
- Defragment or optimize the disk until there is nothing left that can be moved. This will process the disk multiple times in a row.
- -b, –use-system-color-scheme
- Use system color scheme (usually black/white) instead of the green color.
- -p, –suppress-progress-indicator
- Hide progress indicator.
- -v, –show-volume-information
- Show disk information after a job completes.
- -m, –show-cluster-map
- Show a map representing clusters of the disk.
- –map-border-color=color
- Set cluster map border color. Available values: black, white, red, green, blue, yellow, magenta, cyan, darkred, darkgreen, darkblue, darkyellow, darkmagenta, darkcyan, gray. Yellow color is used by default.
- –map-symbol=x
- Set the character used for the map drawing. There are two accepted formats: a character may be typed directly, or its hexadecimal number may be used. For example, –map-symbol=0x1 forces UltraDefrag to use a smile character for the map drawing. Valid numbers are in the range of 0x1 to 0xFF. The % symbol is used by default.
- –map-rows=n
- Number of rows of the cluster map. Default value is 10.
- –map-symbols-per-line=n
- Number of map symbols contained in each row of the map. Default value is 68.
- –use-entire-window
- Expand cluster map to use entire console window.
- –wait
- Wait until already running instance of UltraDefrag completes before starting the job (useful for the scheduled defragmentation).
- –shellex
- This option forces to list objects to be processed and display a prompt to hit any key after a job completion. It is intended for use in Explorer's context menu handler.
Drive letter:
Path:
- Specifying a path will cause UltraDefrag to defragment only the specified path.
- It is possible to specify multiple paths separated by spaces.
- Paths including spaces must be enclosed by double quotes (").
- Relative and absolute paths are supported.
Example: udefrag "%USERPROFILE%" ..\Test "My Documents" C:\WINDOWS\WindowsUpdate.log
- Short paths (like C:\PROGRA~1\SOMEFI~1.TXT) aren't accepted on NT4.
Environment variables
Filter variables
- UD_IN_FILTER
- List of file patterns to be included in the defragmentation process. File patterns must be separated by semicolons.
- UD_EX_FILTER
- List of file patterns to be excluded from the defragmentation process. File patterns must be separated by semicolons.
- UD_FILE_SIZE_THRESHOLD
- Exclude all files larger than the specified size.
The following size suffixes are accepted: KB, MB, GB, TB, PB, EB.
- UD_FRAGMENTS_THRESHOLD
- Exclude all files which have less fragments than the specified number.
- UD_FRAGMENTATION_THRESHOLD
- Set the fragmentation threshold, in percents. When the disk fragmentation level is below the specified value, all the disk processing jobs except of the MFT optimization will be not performed.
Process variables
- UD_TIME_LIMIT
- When the specified time interval elapses the job will be terminated automatically.
The following time format is accepted: Ay Bd Ch Dm Es.
Here A,B,C,D,E represent any integer number, y,d,h,m,s - suffixes represent years, days, hours, minutes and seconds.
- UD_REFRESH_INTERVAL
- Progress refresh interval, in milliseconds. The default value is 100.
- UD_DISABLE_REPORTS
- If this environment variable is set to 1 (one), no file fragmentation report will be generated.
Debug variables
- UD_DBGPRINT_LEVEL
- Control amount of the debugging output. NORMAL is used by default, DETAILED may be used to collect information for the bug report, PARANOID turns on a really huge amount of debugging information.
- UD_LOG_FILE_PATH
- If this variable is set, it should contain the path (including filename) to the log file to save debugging output into.
If the variable is not set, no logging to a file will be performed.
- UD_DRY_RUN
- If this environment variable is set to 1 (one) the files are not physically moved. This allows testing the algorithm without changing the content of the disk.
- Note
- All filters are case insensitive. Each filter substring represents a pattern, UltraDefrag will compare with paths. For example, the "*temp*;<em>tmp</em>" filter will be applied both to temporary folders and to Internet Explorer's cache.
Both '?' and '*' wildcards are accepted by filters. '?' character matches any one character, '*' - any zero or more characters. *.* pattern matches any file with an extension. An asterisk alone (*) matches anything (with or without an extension).
- Note
- Files marked temporary by system are always excluded regardless of filters, because usually they take no effect on system performance.
-
Files excluded from processing are never treated as fragmented. Because only files affecting system performance should get our attention.
Examples
- include only paths, which include one of these words
set UD_IN_FILTER=*windows*;*winnt*
- process only files below 50 MB in size
set UD_FILE_SIZE_THRESHOLD=50MB
- process only files with more than 6 fragments
set UD_FRAGMENTS_THRESHOLD=6
- process only disks with fragmentation level above 10%
set UD_FRAGMENTATION_THRESHOLD=10%
- terminate processing after 6 hours and 30 minutes
- save debugging information to the specified file
set UD_LOG_FILE_PATH=C:\Windows\Temp\defrag_native.log
- defragment drive C:
- list all available drives
- analyze all drives excluding removable ones
- optimize drives E: and K:
- optimize the MFT of drives O: and Q:
udefrag --optimize-mft O: Q:
- defragment the specified file and folder
udefrag C:\Windows\WindowsUpdate.log "C:\Program Files"
Example batch scripts
The following example illustrates defragmentation of a few different disks in series adjusting parameters separately for each disk.
@echo off
set UD_EX_FILTER=*system volume information*;*temp*;*tmp*;*recycle*;*.zip;*.7z;*.rar
set UD_FILE_SIZE_THRESHOLD=50MB
udefrag c: > c:\ud.log
set UD_IN_FILTER=D:\My Documents\*
udefrag d: >> c:\ud.log
set UD_IN_FILTER=
udefrag e: >> c:\ud.log
Notice that we are excluding archives in the script above. Because they are usually rarely accessed and may be left fragmented therefore without noticeable system performance degradation.
The next example demonstrates how the complex disk defragmentation job may be automated easily.
@echo off
rem Defragment small files.
set UD_FILE_SIZE_THRESHOLD=50MB
udefrag c:
rem Defragment large files
rem which have at least 5 fragments.
set UD_FILE_SIZE_THRESHOLD=
set UD_FRAGMENTS_THRESHOLD=5
udefrag c:
The following three commands are very useful in disk defragmentation scripts too:
- chkdsk checks disks for errors and corrects them
- shutdown -s -t 00 automatically shuts down the computer
- hibernate4win now hibernates the computer
The last command is included in the UltraDefrag package. It was especially created to hibernate the computer through the command line after a disk defragmentation, which may take some time to finish.
Explorer's context menu handler
The UltraDefrag command line tool is also used as an Explorer's context menu handler. When you right click a drive, folder or file icon in Explorer, you can select an appropriate menu item to defragment the selected object.
To stop the defragmentation press Ctrl+C keys or close the command prompt.
- Note
- Both UD_IN_FILTER and UD_EX_FILTER environment variables are ignored by the context menu handler. It is intended to defragment exactly what is selected.
Currently the context menu handler is not available in the portable version of the program.