Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Master Command-Line Operations in Windows: A Comprehensive Guide

The command-line interface (CLI) in Windows, commonly accessed via the Command Prompt (CMD) or PowerShell, is a powerful tool for system administration and automation. This article will guide you through using the command-line in Windows, providing practical examples and explanations.


Understanding the Windows Command-Line


Windows offers two primary command-line interfaces:


1. Command Prompt (CMD): An older shell that provides a basic command-line interface.
2. PowerShell: A more advanced shell that supports scripting and automation, offering more capabilities than CMD.


Examples:


1. Navigating the File System:




  • CMD Example:


     C:\> cd \Users\YourUsername\Documents
    C:\Users\YourUsername\Documents> dir

    The cd command changes the directory, and dir lists the contents of the directory.




  • PowerShell Example:


     PS C:\> Set-Location -Path "C:\Users\YourUsername\Documents"
    PS C:\Users\YourUsername\Documents> Get-ChildItem

    Set-Location is the PowerShell equivalent of cd, and Get-ChildItem is similar to dir.




2. Managing Files and Directories:




  • Creating a Directory:


     C:\> mkdir NewFolder



  • PowerShell:


     PS C:\> New-Item -Path "C:\NewFolder" -ItemType Directory



  • Copying Files:


     C:\> copy file.txt C:\NewFolder\



  • PowerShell:


     PS C:\> Copy-Item -Path "file.txt" -Destination "C:\NewFolder\"



3. Network Configuration:




  • Checking IP Configuration:


     C:\> ipconfig



  • PowerShell:


     PS C:\> Get-NetIPAddress



4. File Permissions:




  • Viewing and Modifying Permissions:


     C:\> icacls "C:\NewFolder" /grant YourUsername:F



  • PowerShell:


     PS C:\> $acl = Get-Acl "C:\NewFolder"
    PS C:\> $permission = "YourDomain\YourUsername","FullControl","Allow"
    PS C:\> $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
    PS C:\> $acl.SetAccessRule($accessRule)
    PS C:\> Set-Acl "C:\NewFolder" $acl



5. Running Scripts:




  • Batch Script in CMD:


     @echo off
    echo Hello, World!
    pause



  • PowerShell Script:


     Write-Host "Hello, World!"



Conclusion


The Windows command-line is a versatile tool that can significantly enhance your productivity and system management capabilities. Whether you choose CMD for its simplicity or PowerShell for its advanced features, mastering these tools is invaluable for any Windows systems engineer.


To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.