udefrag command

Last updated on Jul 3, 2021

The core component of UltraDefrag CLI is the udefrag command. You can analyze, defragment and optimize disks using it. Also you can use it to get the list of disks available for defragmentation.

UltraDefrag installs the udefrag command to the %SystemRoot%\system32 directory, so it can be accessed without the full path specification. The only requirement is you have to launch it from an elevated command prompt as it requires administrative rights.

Synopsis

udefrag [action] [options] [disks] [paths]

Actions

ActionDescription
-a, --analyzeAnalyze the specified disks.
-o, --optimizePerform the full optimization of the specified disks.
-q, --quick-optimizationPerform the quick optimization of the specified disks.
--optimize-mftOptimize master file tables on the specified disks.
-l, --list-available-volumesList all non-removable disks available for defragmentation.
-la, --list-available-volumes=allList all disks available for defragmentation, including removable ones.
-?, -h, --helpDisplay a help screen.

The actions are exclusive and cannot be combined with each other. If no action is specified the program will defragment the specified disks and paths. If neither disks nor paths are specified as well the program will display a help screen.

Options

OptionDescription
--deepPerform a deep processing of the specified disks and paths. If this option is present on the command line the program will process all files ignoring all the environment variables which control exclusion of files from the processing.
-b, --use-system-color-schemeDisable colorization of output.
-p, --suppress-progress-indicatorDo not display the progress indicator and the cluster map.
-v, --show-volume-informationDisplay statistics after the job completion.
-m, --show-cluster-mapDisplay the cluster map.
--map-border-color=<color>Set the cluster map border color. Available colors are: black, white, red, green, blue, yellow, magenta, cyan, darkred, darkgreen, darkblue, darkyellow, darkmagenta, darkcyan, gray. By default the program uses the yellow color.
--map-symbol=<symbol>Select a character do draw the cluster map with. The character can be specified either directly or via its ASCII code in the hexadecimal form (in the range of 0x1…0xFF). By default the program uses the % character.
--map-rows=<n>Set the cluster map height. By default the map is 10 rows high.
--map-symbols-per-line=<n>Set the cluster map width. By default the map is 68 characters wide.
--use-entire-windowExpand the cluster map to use all the available space.
--waitWait for completion of defragmentation jobs running in other UltraDefrag instances before the job startup.
--shellexProcess the specified disks and paths in a special mode which UltraDefrag uses for the one-click defragmentation of individual files and folders. In this mode the program displays the list of selected objects before the job startup and a prompt to hit any key after the job completion. Also it ignores environment variables and takes into account the user preferences instead.

Disks and paths

You can analyze, defragment and optimize multiple disks in one go:

1
udefrag c: d:

Also you can use one of the following switches:

SwitchDescription
--allProcess all available disks.
--all-fixedProcess all non-removable disks.

Sometimes you may want to defragment individual files and folders rather than the entire disks. To accomplish that specify a space separated list of paths you want to defragment. Both absolute and relative paths are supported, as well as the * and ? wildcards. All the paths containing spaces must be enclosed by double quotes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
:: defragment the USERPROFILE folder contents
udefrag "%USERPROFILE%\*"

:: defragment everything inside of the '..\Test Files' folder

udefrag "..\Test Files\*"

:: defragment an individual file

udefrag "C:\Virtual Machines\Windows 10\Windows 10.vmdk"

:: defragment them all at once

udefrag "%USERPROFILE%\*" "..\Test Files\*" "C:\Virtual Machines\Windows 10\Windows 10.vmdk"

:: defragment the WINDOWS folder itself (its contents will be not processed)

udefrag C:\WINDOWS

Environment variables

Unless the --shellex option is specified on the command line the command line interface does not take into account the user preferences. Instead, it takes into account the following environment variables:

Variable nameDescription
UD_IN_FILTERIf this variable is set, UltraDefrag defragments only the specified files. Multiple patterns can be specified, separated by semicolons. The patterns do support the ? and * wildcards. For instance, you can set the variable to C:\Windows\*;C:\Program Files\* to process only files from C:\Windows and C:\Program Files directories.
UD_EX_FILTERIf this variable is set, UltraDefrag excludes all the specified files from defragmentation. Multiple patterns can be specified, separated by semicolons. The patterns do support the ? and * wildcards. For instance, you can set the variable to *tmp*;*temp* to exclude temporary files.
UD_FRAGMENT_SIZE_THRESHOLDIf this variable is set, UltraDefrag skips fragments bigger than specified during defragmentation. The following unit symbols are supported: KB, MB, GB, TB, PB, EB. For instance, you can set the variable to 20 MB to skip all fragments bigger than 20 megabytes.[1]
UD_FILE_SIZE_THRESHOLDIf this variable is set, UltraDefrag skips files bigger than specified during defragmentation. The following unit symbols are supported: KB, MB, GB, TB, PB, EB. For instance, you can set the variable to 20 MB to skip all files bigger than 20 megabytes.[1]
UD_OPTIMIZER_FILE_SIZE_THRESHOLDIf this variable is set, UltraDefrag skips files bigger than specified during the disk optimization. The following unit symbols are supported: KB, MB, GB, TB, PB, EB. For instance, you can set the variable to 20 MB to skip all files bigger than 20 megabytes.[1] If the variable is not set, UltraDefrag uses the default value which is 20 MB.
UD_FRAGMENTS_THRESHOLDIf this variable is set, UltraDefrag skips all files having less fragments than specified, during defragmentation. For instance, you can set this variable to 20 to skip all files having less than 20 fragments.
UD_SORTINGUse this variable to set the sorting criteria for the disk optimization. Available values are: PATH (sort files by path), SIZE (sort files by size), C_TIME (sort files by the creation time), M_TIME (sort files by the last modification time) and A_TIME (sort files by the last access time). If the variable is not set, UltraDefrag sorts files by path during the disk optimization.
UD_SORTING_ORDERUse this variable to set the sorting order for the disk optimization. Available values are: ASC (sort files in ascending order) and DESC (sort files in descendig order). If the variable is not set, UltraDefrag sorts files in ascending order during the disk optimization.
UD_FRAGMENTATION_THRESHOLDIf this variable is set, UltraDefrag skips disks having the fragmentation level lower than specified entirely during all the operations except of the master file table optimization. For instance, you can set this variable to 10 to skip all disks which have the fragmentation level below 10%.
UD_TIME_LIMITYou can use this variable to limit the disk processing time. UltraDefrag uses the following time format: Ad Bh Cm Ds, where A, B, C, D are integer numbers and d, h, m, s represent days, hours, minutes and seconds respectively. For instance, you can set the variable to 6h 30m to limit the disk processing time by 6 hours and 30 minutes.
UD_REFRESH_INTERVALYou can use this variable to set the progress refresh interval in milliseconds. For instance, you can set this variable to 1000 to refresh the progress indicators one time a second. If the variable is not set, UltraDefrag uses the default value of 100 milliseconds, i.e. one tenth of a second.
UD_DISABLE_REPORTSSet this variable to 1 to disable generation of the file fragmentation reports.
UD_DBGPRINT_LEVELYou can use this variable to control the amount of debugging output. The available values are: NORMAL (generate a moderate amount of debugging output), DETAILED (generate more debugging output) and PARANOID (generate a lot of debugging output). If the variable is not set, UltraDefrag generates a moderate amount of debugging output.
UD_LOG_FILE_PATHIf this variable is set, UltraDefrag saves the debugging output to the specified file.
UD_DRY_RUNSet this variable to 1 to perform the disk processing in a quick test mode. In this mode UltraDefrag does not actually move files on the disk, but everything else works the same way as in normal operation.

Tip

You can easily set the environment variables according to the user preferences using the setenv command.

Notes