Throughout the evolution of computer history, the command line interface (
CLI
) has always been a central component that provides users with the ability to interact directly with computer systems. Command-line tools have come a long way from early text interfaces to modern terminals.
This article will deeply explore the characteristics, history and application of the five tools (systems) of DOS, CMD, PowerShell, Shell and Windows Terminal.
Article directory
1. Concept
1.1 DOS (Disk Operating System)
-
Definition : DOS was the mainstream operating system in the early 1980s , primarily used on IBM PC-compatible personal computers.
-
History and Development :
- DOS was originally developed for IBM's first personal computer.
- MS-DOS is the most popular version, developed by Microsoft.
- DOS waned in importance with the advent of Windows, but it laid the groundwork for subsequent command-line tools .
-
Main application :
- file management.
- System Configuration.
- Run earlier applications.
1.2 CMD (Command Prompt)
-
Definition : CMD is the command line interpreter of the Windows operating system , which inherits many features of MS-DOS.
-
History and Development :
- CMD first appeared in Windows NT as a replacement for MS-DOS.
- It provides better integration with Windows systems, while retaining the core functionality of MS-DOS.
-
Main application :
- File and directory operations.
- Network diagnostics.
- System Management.
1.3 PowerShell
-
Definition : PowerShell is a cross-platform task automation and configuration management framework developed by Microsoft.
-
History and Development :
- PowerShell was originally developed for Windows Vista to provide a more powerful scripting environment than CMD .
- It is now a core component of Windows Server and Azure cloud services.
-
Main application :
- System automation.
- configuration management.
- Data processing and analysis.
1.4 Shell
-
Definition : Shell is
Linux
the command line interpreterUnix
of the system . -
History and Development :
- The Unix Shell was originally developed for the Unix operating system and has since been adopted by many other systems.
Bash
is the most popular shell, but there are other options such as Zsh, Fish, and Tcsh.
-
Main application :
- File and process management.
- Script programming.
- System monitoring.
1.5 Windows Terminal
-
Definition : Windows Terminal is Microsoft's new terminal application that provides an integrated environment that supports CMD, PowerShell, and WSL .
-
History and Development :
- Windows Terminal is Microsoft's answer to the modern terminal, and it was first released in 2019 .
- Its goal is to provide a unified, efficient and highly customizable terminal experience.
-
Main application :
- Multi-tab interface.
- Rich visual effects and themes.
- High degree of user customization.
In fact, a large number of users rarely use the Windows terminal, but use cmd or powershell directly as before it was launched. But the experience of Windows terminal is really good. For example, more lines can be displayed. Even if the buffer is pulled to the maximum in powershell, the output of some commands cannot be displayed in full, and paging or output redirection is required, while in Windows terminal it can be Displays thousands of lines (not practical though).
Unlike the Windows terminal, the terminal of the Unix-like system has more powerful functions. In addition to accessing the shell (command interpreter), it also provides many other functions, such as application execution (vim), remote access, script execution, and so on. It 's more of a command interpreter itself (although it's not).
1.51 Linux terminal
A Linux terminal, often referred to as a "terminal emulator" or simply "terminal," is a software program that provides a user with a text interface to interact with a Linux system. It emulates the physical terminals of early computers that used a text interface rather than a graphical interface.
Here are some key features and functions of the Linux terminal:
-
Command Line Interface : Terminal provides a command line interface where users can enter commands to perform various tasks such as file management, system monitoring, and software installation.
-
Shell access : Through the terminal, users can access the system's shell (such as Bash, Zsh, or Fish). Shell is a command line interpreter that reads and executes commands entered by the user.
-
Script execution : Users can execute shell scripts in the terminal, which can automate many tasks.
-
Text interface applications : Some Linux applications, such as text editors
vim
ornano
, and file managersmc
, are text-based and run in a terminal. -
Remote access : Through tools such as
ssh
(secure shell), users can remotely access the terminal of another Linux system from one terminal. -
Variety : Linux has a variety of terminal emulators to choose from, such as
gnome-terminal
,konsole
,xterm
andterminator
, each with its own unique features and functions. -
Highly customizable : Most terminal emulators allow users to customize their appearance and behavior, such as changing fonts, colors, backgrounds, and shortcut keys.
1.52 MacOS Terminal
The terminal for macOS is similar in many ways to the terminal for Linux because macOS is based on Unix. Here are some key features and capabilities of macOS Terminal:
-
Command-line interface : Terminal for macOS provides a command-line interface that allows users to enter commands to perform various tasks such as file management, network diagnostics, and system configuration.
-
Bash Shell : Until macOS Catalina, the default shell for macOS was Bash. Starting with macOS Catalina, the system default shell has changed to Zsh, but users can still choose to use Bash or other shells.
-
Script execution : Like the Linux terminal, the macOS terminal allows users to execute shell scripts to automate tasks.
-
Built-in tools : macOS Terminal provides many Unix tools, such as
grep
,awk
, ,sed
andssh
etc. -
Homebrew : macOS users often use Homebrew as a package manager to install additional command-line tools and applications.
-
Remote Access : macOS Terminal has built-in
ssh
tools that allow users to access other systems remotely. -
Highly customizable : macOS Terminal supports multiple tabs and windows, and users can customize fonts, colors, and other appearance settings.
-
Other Terminal Apps : In addition to the default Terminal.app, macOS has other third-party Terminal apps, such as iTerm2, which offer even more features and customization options.
-
Integrated Development Environment (IDE) integration : Many modern IDEs, such as Visual Studio Code or PyCharm, provide integrated terminals that allow developers to write code and execute commands in the same interface.
2. Commonly used commands (a small part)
2.1 DOS (Disk Operating System)
DOS is a text-based operating system whose commands are mainly used for file and directory management. Here are some commonly used DOS commands:
DIR
: List files and subdirectories in a directory.COPY
: Copy files.DEL
:Delete Files.REN
: Rename the file.CD
: Change the current directory.MKDIR
(orMD
): Create a new directory.RMDIR
(orRD
): Delete a directory.TYPE
: Display file content.
2.2 CMD (Command Prompt)
CMD is a command line interpreter for Windows, which inherits some commands from DOS and adds some new functions . Here are some commonly used CMD commands:
CLS
: Clear the screen.ECHO
: Display a message or turn on/off echo.FC
: Compares two files and displays the differences.FIND
: Find a string in the file.IPCONFIG
: Display network configuration information.NET
: Used to manage network resources.SYSTEMINFO
: Display the system information of the computer.TASKLIST
: Displays the currently running processes.
2.3 PowerShell
PowerShell is a powerful scripting environment that provides a large number of commands (called cmdlet
) to perform various tasks. Here are some commonly used PowerShell commands (commands are basically predicate-object structures):
Get-Command
: Lists all available cmdlets and functions.Get-Help
: Display the help information of the cmdlet.Get-Process
: List all running processes.Get-Service
: List all services and their status.Set-ExecutionPolicy
: Set the script execution policy.ConvertTo-Json
: Convert the object to JSON format.Invoke-WebRequest
: Send a web request.Export-Csv
: Export the object as a CSV file.
Many cmd commands are also available in powershell, but there are differences:
-
Command Compatibility : PowerShell can execute most CMD commands because it allows running external programs. So, you can run traditional CMD commands like
dir
,ipconfig
, etc. in PowerShell .netstat
-
Aliases : In order to maintain a certain compatibility with CMD, PowerShell provides aliases for many commonly used CMD commands. For example, when you type in PowerShell
dir
, it actually callsGet-ChildItem
the cmdlet. This means that you can use familiar CMD commands in PowerShell, but PowerShell cmdlets are actually executed behind the scenes. -
Command Structure : Although PowerShell supports many CMD commands, they may work differently. PowerShell uses the structure of cmdlets, which generally follow
Verb-Noun
naming conventions such asGet-Content
, ,Set-Item
and so on. -
Parameter differences : Even though some CMD commands work in PowerShell, their parameters and work may be different than in CMD. For example, some commands may require PowerShell's parameter prefixes
-
instead of CMD's/
. -
Extended functionality : PowerShell provides many features that do not exist in CMD, such as object pipeline, remote management, and rich scripting capabilities.
-
Security : PowerShell has an execution policy system that may prevent certain scripts from executing unless the user explicitly allows it. This is for added security against the execution of malicious scripts.
Although PowerShell supports many traditional CMD commands, they may work differently, or have different parameters and functionality. To get the most out of PowerShell, users are advised to learn and use its native cmdlets and functionality, rather than relying solely on legacy CMD commands.
2.4 Shell (such as Bash)
Bash is the most commonly used shell on Linux and Unix systems. Here are some commonly used Bash commands:
ls
: List directory contents.cd
: Change the current directory.pwd
: Display the current working directory.echo
: Output text or variable.grep
: Search for specific text in the file.chmod
: Change the permissions of a file or directory.chown
: Change the owner of a file or directory.ps
: Displays the currently running processes.kill
:end process.
2.5 Use CMD or Powershell
2.51 Overall Comparison
CMD
(Command Prompt) and PowerShell
both are command-line interfaces in the Windows operating system, but they differ in design, function, and purpose. Here's a comparison of the two:
CMD
(command prompt):
- History : CMD is a traditional command line tool for Windows, which inherits the command set of MS-DOS.
- Function : Relatively basic, it mainly provides file and directory management functions.
- Scripting : Use batch (.bat) files for scripting.
- Compatibility : Due to its long history, some old applications and scripts may still depend on CMD.
- Interface : Text based, no advanced text processing or object manipulation features built in.
PowerShell
:
- History : PowerShell is a modern command-line and scripting environment for Windows, first released in 2006.
- Features : Very powerful, offering many advanced features such as remote management, event log access, and registry manipulation.
- Scripts : Use .ps1 script files and support more complex programming structures and operations.
- Object-oriented : PowerShell is object-based, which means that the output of commands can be treated as objects, not just text. This makes data processing and manipulation more flexible and powerful.
- Extensibility : PowerShell supports modules and extensions, allowing users to add more commands and functions.
- Cross-platform : PowerShell Core is an open-source version of PowerShell that runs on Windows, Linux, and macOS.
suggestion:
- For basic file and directory management tasks, both CMD and PowerShell are capable, but PowerShell provides more advanced features.
- If you need to do complex scripting, data manipulation, or system administration tasks, PowerShell is definitely the better choice.
- For users who are accustomed to using traditional DOS commands, CMD may be more familiar.
- PowerShell is the recommended tool for users looking to learn modern command line skills and take advantage of the full power of Windows systems.
Choosing CMD or PowerShell depends on your specific needs, experience, and complexity of tasks. However, over time, Microsoft has clearly leaned more toward promoting and supporting PowerShell as its primary command-line tool.
2.52 Script comparison
CMD
and PowerShell
scripts differ significantly in syntax, functionality, and design philosophy. Here are the main differences between the two scripts:
-
Script file extension:
- CMD : Use
.bat
or.cmd
as an extension for batch scripts. - PowerShell : Use
.ps1
as an extension for PowerShell scripts.
- CMD : Use
-
grammar:
-
CMD : The syntax of batch scripts is relatively simple, mainly based on early DOS commands. For example, use
echo
to print text, useif
to perform conditional judgment, usefor
to perform looping, etc. -
PowerShell : The syntax of PowerShell is richer and more powerful. It supports more complex programming constructs such as functions, arrays, hash tables, object handling, etc. PowerShell commands usually follow
Verb-Noun
the naming convention of , such asGet-ChildItem
,Set-Variable
etc.
-
-
Function:
-
CMD : Batch scripts have relatively limited functions and are mainly used for file and directory management, simple text processing and system tasks.
-
PowerShell : PowerShell provides many advanced features such as remote management, event log access, registry operations, WMI query, Active Directory management, etc.
-
-
data processing:
-
CMD : Batch scripts mainly process text data. Text processing is limited and often requires the use of external tools such as
findstr
text search and replace. -
PowerShell : PowerShell is object-based, which means that the output of commands can be treated as objects, not just text. This makes data processing and manipulation more flexible and powerful.
-
-
Error handling:
-
CMD : Error handling for batch scripts is relatively simple, often using
errorlevel
a variable to check the exit status of the previous command. -
PowerShell : PowerShell provides more advanced error handling mechanisms, such as
try-catch-finally
structs, and detailed access to error objects.
-
-
safety:
-
CMD : Batch scripts have no built-in security mechanisms.
-
PowerShell : PowerShell has an execution policy system that prevents unauthorized script execution. Additionally, PowerShell scripts can be digitally signed to ensure their integrity and origin.
-
PowerShell scripts provide more powerful and flexible functionality than batch scripts. While batch scripts are still useful for some simple tasks, PowerShell is a better choice for complex system administration and automation tasks.
Write love you forever into the end of the poem ~