|  | UltraDefrag Handbook 7.1.1

Console Interface

UltraDefrag command line (console) interface can be used to automate defragmentation via batch scripts and scheduled tasks. Also it can be used instead of the graphical interface by those who prefer command line environment.

Also UltraDefrag uses its command line interface to handle its context menu entries in Windows Explorer. Right click any object and select Defragment with UltraDefrag to rejoin its clusters. To stop defragmentation hit Ctrl+C or close the command prompt. To configure the context menu handler click Settings > Options in UltraDefrag GUI or edit the following file manually: {installation folder}\conf\options.lua.

Note
  The context menu handler is not available from the portable edition of the program.

UltraDefrag puts its command line tool to the %SystemRoot%\system32 folder, so it can be used without the full path specification. Just make sure you run it from an elevated command prompt as it requires administrative rights.

Usage:

udefrag [command] [options] [driveletter:] [path(s)]

Commands:

-a, --analyze
  Analyze specified objects.

-o, --optimize
  Perform full optimization.

-q, --quick-optimization
  Perform quick optimization.

--optimize-mft
  Optimize master file tables only.

-l, --list-available-volumes
  List all fixed disks available for defragmentation.

-la, --list-available-volumes=all
  List all available disks, including removable.

-h, -?, --help
  Display help.

Note
  The commands are exclusive and can't be combined with each other. If none is specified the program defragments selected objects.

Options:

-b, --use-system-color-scheme
  Disable colorization of output.

-p, --suppress-progress-indicator
  Hide the progress indicator and the cluster map.

-v, --show-volume-information
  Show disk information after the job completion.

-m, --show-cluster-map
  Show the cluster map.

--map-border-color=color
  Set color of the cluster map border. Available colors: black, white, red, green, blue, yellow, magenta, cyan, darkred, darkgreen, darkblue, darkyellow, darkmagenta, darkcyan, gray. Yellow is used by default.

--map-symbol=x
  Set the character to draw the cluster map with. Type it directly or use its hexadecimal number (in range 0x1 ... 0xFF). For instance, use --map-symbol=0x1 to draw the map with a smile character. The % symbol is used by default.

--map-rows=n
  Set height of the cluster map. The default value is 10.

--map-symbols-per-line=n
  Set width of the cluster map. The default value is 68.

--use-entire-window
  Expand the cluster map to use the entire console window.

--wait
  Wait for completion of other UltraDefrag instances before the job startup (useful for scheduled tasks).

--shellex
  List selected objects and display a prompt to hit any key after the job completion. This switch is intended to handle the context menu entries in Windows Explorer, so the program interpretes the options.lua file mentioned above and ignores all the environment variables listed below.

Drive letters:

List of space separated drive letters or one of the following switches:

--all
  Process all available drives.

--all-fixed
  Process all non-removable drives.

Paths:

List of space separated paths which need to be defragmented. Both absolute and relative paths are supported, as well as wildcards: the question mark (?) matches any one character, while the asterisk (*) - any zero or more characters. Thus *.* matches any file with an extension while a single asterisk (*) matches anything (with or without an extension). All paths including spaces must be enclosed by double quotes:

:: defragment drives d: and e:
udefrag d: e:
:: defragment the contents of the USERPROFILE folder
udefrag "%USERPROFILE%\*"
:: defragment everything inside of the '..\Test Files' folder
udefrag "..\Test Files\*"
:: defragment some individual file
udefrag C:\WINDOWS\WindowsUpdate.log
:: defragment them all at once
udefrag d: e: "%USERPROFILE%\*" "..\Test Files\*" C:\WINDOWS\WindowsUpdate.log
:: rejoin clusters of the WINDOWS folder
:: (its contents will be left untouched)
udefrag C:\WINDOWS

If command line is empty the program displays help.

# Environment variables

## Filter variables

UD_IN_FILTER
  List of semicolon separated paths which need to be defragmented.
  Empty list means that everything needs to be defragmented.

UD_EX_FILTER
  List of semicolon separated paths which need to be skipped, i.e. left untouched.

UD_FRAGMENT_SIZE_THRESHOLD
  Eliminate only fragments smaller than specified.
  The following size suffixes are accepted: KB, MB, GB, TB, PB, EB.

UD_FILE_SIZE_THRESHOLD
  Exclude all files larger than specified.
  The following size suffixes are accepted: KB, MB, GB, TB, PB, EB.

UD_OPTIMIZER_FILE_SIZE_THRESHOLD
  For optimization only, exclude all files larger than specified.
  The following size suffixes are accepted: KB, MB, GB, TB, PB, EB.
  The default value is 20MB.

UD_FRAGMENTS_THRESHOLD
  Exclude files having less fragments than specified.

UD_SORTING
  Set sorting criteria for the disk optimization. PATH is used by default, it forces to sort files by their paths. Four more options are available: SIZE (sort by size), C_TIME (sort by creation time), M_TIME (sort by last modification time) and A_TIME (sort by last access time).

UD_SORTING_ORDER
  Set sorting order for the disk optimization. ASC (ascending) is used by default. DESC (descending) forces to sort files in reverse order.

UD_FRAGMENTATION_THRESHOLD
  Cancel all tasks except of the MFT optimization when the disk fragmentation level is below than specified.

## Process variables

UD_TIME_LIMIT
  Terminate the job automatically when the specified time interval elapses. The following time format is accepted: Ay Bd Ch Dm Es. Here A,B,C,D,E represent integer numbers while y,d,h,m,s represent years, days, hours, minutes and seconds.

UD_REFRESH_INTERVAL
  The progress refresh interval, in milliseconds. The default value is 100.

UD_DISABLE_REPORTS
  Set it to 1 (one) to disable generation of the file fragmentation reports.

## Debugging variables

UD_DBGPRINT_LEVEL
  Set amount of debugging output. NORMAL is used by default, DETAILED can be used to collect information for a bug report, PARANOID turns on really huge amount of debugging information.

UD_LOG_FILE_PATH
  Set log file path (including file name) to redirect debugging output to a file.

UD_DRY_RUN
  Set it to 1 (one) to avoid physical movements of files, i.e. to simulate the disk processing. This allows to check out algorithms quickly.

# Samples

Batch scripts can be used to automate complex defragmentation tasks:

@echo off
:: save debugging information for troubleshooting
set UD_LOG_FILE_PATH=C:\Windows\Temp\udefrag.log
:: terminate the processing after 6 hours and 30 minutes
set UD_TIME_LIMIT=6h 30m
:: exclude temporary stuff
set UD_EX_FILTER=*system volume information*;*temp*;*tmp*;*recycle*
:: exclude archives as well
set UD_EX_FILTER=%UD_EX_FILTER%;*.zip;*.7z;*.rar
:: eliminate only fragments below 20 MB in size
set UD_FRAGMENT_SIZE_THRESHOLD=20MB
:: list all drives available for defragmentation
udefrag -la
:: check all available drives for errors
for /F "tokens=1 skip=8" %%D in ('udefrag -la') do chkdsk %%D
:: analyze all fixed drives
udefrag -a --all-fixed
:: defragment everything on drive c:
udefrag c:
:: defragment small audio files on drive d:
set UD_IN_FILTER=*.mp3
set UD_FILE_SIZE_THRESHOLD=20MB
udefrag "D:\My Docs\Music\*"
:: defragment large video files having at least 10 fragments
set UD_IN_FILTER=*.avi;*.mkv
set UD_FILE_SIZE_THRESHOLD=
set UD_FRAGMENTS_THRESHOLD=10
udefrag "D:\My Docs\Movies\*"
:: optimize master file tables on drives c: and d:
udefrag --optimize-mft c: d:
:: reset filters used above
set UD_IN_FILTER=
set UD_FRAGMENTS_THRESHOLD=
:: sort files on drive g: by creation time in descending order
set UD_SORTING=C_TIME
set UD_SORTING_ORDER=DESC
udefrag -o g:
:: defragment drive h: only if its fragmentation level is above 10%
set UD_FRAGMENTATION_THRESHOLD=10
udefrag h:
:: defragment all fixed disks except of c:, d:, g: and h:
set UD_EX_FILTER=%UD_EX_FILTER%;C:\*;D:\*;G:\*;H:\*
udefrag --all-fixed
:: defragment a disk with no drive letter assigned,
:: mounted to C:\Games, using the diskpart utility
:: first of all, assign a drive letter to the disk
echo select volume c:\games > script
echo assign letter=t >> script
diskpart /s script
:: then, defragment the disk
udefrag t:
:: after all, remove the assigned letter
echo select volume c:\games > script
echo remove letter=t >> script
diskpart /s script
:: hibernate the computer using a special
:: command line tool shipped with UltraDefrag
hibernate4win now
:: shut the computer down if hibernation failed
if errorlevel 1 shutdown -s -t 00

Previous: Graphical Interface | Next: Boot Time Defragmentation