How to use the command 'doskey' (with examples)
- Windows
- December 25, 2023
The ‘doskey’ command is a Windows command-line tool that is used to manage macros, Windows commands, and command-lines. It provides various functions such as listing available macros, creating new macros, removing macros, displaying command history, and saving/loading macros to/from a file.
Use case 1: List available macros
Code:
doskey /macros
Motivation: This use case is helpful when you want to see a list of all the macros that have been defined in the command prompt.
Explanation: The ‘/macros’ argument is used to display a list of all available macros in the command prompt.
Example output:
clear=cls
ls=dir
Use case 2: Create a new macro
Code:
doskey name = "command"
Motivation: This use case allows you to create a new macro in the command prompt, making it easier to execute a complex or frequently used command.
Explanation: The ’name’ represents the name of the new macro, and ‘command’ represents the command or set of commands that the macro will execute.
Example:
doskey count = for /L %i in (1,1,10) do @echo %i
Use case 3: Create a new macro for a specific executable
Code:
doskey /exename=executable name = "command"
Motivation: This use case is helpful when you want to create a new macro specifically for a certain executable or program.
Explanation: The ‘/exename=executable’ argument is used to specify the name of the executable for which the macro is meant. ’name’ represents the name of the new macro, and ‘command’ represents the command or set of commands that the macro will execute.
Example:
doskey /exename=python3 py = python.exe
Use case 4: Remove a macro
Code:
doskey name =
Motivation: This use case allows you to remove a macro from the command prompt that is no longer needed or has been defined incorrectly.
Explanation: The ’name’ represents the name of the macro that you want to remove. By assigning an empty value after the equals sign ‘=’, the macro will be removed.
Example:
doskey count =
Use case 5: Display all commands that are stored in memory
Code:
doskey /history
Motivation: This use case is useful when you want to view the command history and recall previously executed commands.
Explanation: The ‘/history’ argument is used to display all the commands that are stored in memory, providing a history of the executed commands.
Example output:
dir
cd ..
echo Hello, world!
Use case 6: Save macros to a file for portability
Code:
doskey /macros > path\to\macinit_file
Motivation: This use case allows you to save all the defined macros into a file. This can be useful for portability, as you can load the macros from the file on different machines or at a later time.
Explanation: The ‘/macros’ argument is used to export all the macros, and the ‘>’ sign is used to redirect the output to a file specified by ‘path\to\macinit_file’.
Example command:
doskey /macros > C:\Users\username\macros.txt
Use case 7: Load macros from a file
Code:
doskey /macrofile = path\to\macinit_file
Motivation: This use case allows you to load macros from a saved file that contains previously defined macros.
Explanation: The ‘/macrofile’ argument is used to specify the file from which to load the macros. The file should contain the macros in the correct format.
Example:
doskey /macrofile = C:\Users\username\macros.txt
Conclusion:
The ‘doskey’ command is a versatile tool for managing macros, Windows commands, and command-lines in the Windows command prompt. By utilizing the various use cases described above, you can enhance your productivity and streamline your command-line usage.