The difference between DOS, CMD, PowerShell, Shell and Windows (Unix-like) Terminal

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.

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 Linuxthe 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.
    • Bashis 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).
insert image description here


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:

  1. 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.

  2. 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.

  3. Script execution : Users can execute shell scripts in the terminal, which can automate many tasks.

  4. Text interface applications : Some Linux applications, such as text editors vimor nano, and file managers mc, are text-based and run in a terminal.

  5. Remote access : Through tools such as ssh(secure shell), users can remotely access the terminal of another Linux system from one terminal.

  6. Variety : Linux has a variety of terminal emulators to choose from, such as gnome-terminal, konsole, xtermand terminator, each with its own unique features and functions.

  7. 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:

  1. 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.

  2. 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.

  3. Script execution : Like the Linux terminal, the macOS terminal allows users to execute shell scripts to automate tasks.

  4. Built-in tools : macOS Terminal provides many Unix tools, such as grep, awk, , sedand sshetc.

  5. Homebrew : macOS users often use Homebrew as a package manager to install additional command-line tools and applications.

  6. Remote Access : macOS Terminal has built-in sshtools that allow users to access other systems remotely.

  7. Highly customizable : macOS Terminal supports multiple tabs and windows, and users can customize fonts, colors, and other appearance settings.

  8. 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.

  9. 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(or MD): Create a new directory.
  • RMDIR(or RD): 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:

  1. 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

  2. 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 calls Get-ChildItemthe cmdlet. This means that you can use familiar CMD commands in PowerShell, but PowerShell cmdlets are actually executed behind the scenes.

  3. Command Structure : Although PowerShell supports many CMD commands, they may work differently. PowerShell uses the structure of cmdlets, which generally follow Verb-Nounnaming conventions such as Get-Content, , Set-Itemand so on.

  4. 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 /.

  5. Extended functionality : PowerShell provides many features that do not exist in CMD, such as object pipeline, remote management, and rich scripting capabilities.

  6. 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 PowerShellboth 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):

  1. History : CMD is a traditional command line tool for Windows, which inherits the command set of MS-DOS.
  2. Function : Relatively basic, it mainly provides file and directory management functions.
  3. Scripting : Use batch (.bat) files for scripting.
  4. Compatibility : Due to its long history, some old applications and scripts may still depend on CMD.
  5. Interface : Text based, no advanced text processing or object manipulation features built in.

PowerShell

  1. History : PowerShell is a modern command-line and scripting environment for Windows, first released in 2006.
  2. Features : Very powerful, offering many advanced features such as remote management, event log access, and registry manipulation.
  3. Scripts : Use .ps1 script files and support more complex programming structures and operations.
  4. 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.
  5. Extensibility : PowerShell supports modules and extensions, allowing users to add more commands and functions.
  6. 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

CMDand PowerShellscripts differ significantly in syntax, functionality, and design philosophy. Here are the main differences between the two scripts:

  1. Script file extension:

    • CMD : Use .bator .cmdas an extension for batch scripts.
    • PowerShell : Use .ps1as an extension for PowerShell scripts.
  2. grammar:

    • CMD : The syntax of batch scripts is relatively simple, mainly based on early DOS commands. For example, use echoto print text, use ifto perform conditional judgment, use forto 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-Nounthe naming convention of , such as Get-ChildItem, Set-Variableetc.

  3. 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.

  4. data processing:

    • CMD : Batch scripts mainly process text data. Text processing is limited and often requires the use of external tools such as findstrtext 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.

  5. Error handling:

    • CMD : Error handling for batch scripts is relatively simple, often using errorlevela variable to check the exit status of the previous command.

    • PowerShell : PowerShell provides more advanced error handling mechanisms, such as try-catch-finallystructs, and detailed access to error objects.

  6. 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 ~

Guess you like

Origin blog.csdn.net/weixin_43764974/article/details/132251532