🐂 🆚 ✴️ Vários comandos do dia a dia usados no terminal do GNU e equivalentes em PowerShell.
No mundo da automação de tarefas, dominar a linha de comando é uma habilidade essencial. Seja com os tradicionais , com o poderoso : C:\Program Files\Terlang\bin(Windows) e ${HOME}/.local/terlang/bin/(GNU)
🐂 GNU
export PATH="${PATH}:${HOME}/.local/terlang/bin/"
✴️ PowerShell
[System.Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Terlang\bin", [System.EnvironmentVariableTarget]::Machine)
💻 22. Exibir últimas linhas de um arquivo (tail)
🐂 GNU
tail -n 20 file.log
✴️ PowerShell
Get-Content file.log -Tail 20
💻 23. Exibir processos em tempo real (top)
🐂 GNU
top
✴️ PowerShell
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
(não é em tempo real, mas dá um snapshot dos processos com maior uso de CPU)
💻 24. Buscar e matar processo por nome
🐂 GNU
pkill -f processo
✴️ PowerShell
Get-Process -Name processo | Stop-Process -Force
💻 25. Monitorar alterações em arquivo (tail -f)
🐂 GNU
tail -f file.log
✴️ PowerShell
Get-Content file.log -Wait
💻 26. Compactar arquivos (tar gzip)
🐂 GNU
tar -czvf archive.tar.gz folder/
✴️ PowerShell
Compress-Archive -Path folder\* -DestinationPath archive.zip
💻 27. Descompactar arquivo zip
🐂 GNU
unzip archive.zip
✴️ PowerShell
Expand-Archive -Path archive.zip -DestinationPath destino\
💻 28. Visualizar variáveis de ambiente específicas
🐂 GNU
echo $VARIAVEL
✴️ PowerShell
$env:VARIAVEL
💻 29. Definir variável de ambiente para a sessão atual
🐂 GNU
export VARIAVEL=valor
✴️ PowerShell
$env:VARIAVEL="valor"
💻 30. Exibir informações do sistema (kernel, SO)
🐂 GNU
uname -a
✴️ PowerShell
Get-CimInstance Win32_OperatingSystem | Select-Object Caption, Version, OSArchitecture
💻 31. Ver horário e data atual
🐂 GNU
date
✴️ PowerShell
Get-Date
💻 32. Exibir quem está logado no sistema
🐂 GNU
who
✴️ PowerShell
query user
💻 33. Ver portas TCP abertas e processos associados
🐂 GNU
sudo netstat -tulpn
✴️ PowerShell
Get-NetTCPConnection | Select-Object LocalAddress,LocalPort,OwningProcess
💻 34. Buscar arquivos pelo nome
🐂 GNU
find /path -name "arquivo.txt"
✴️ PowerShell
Get-ChildItem -Path C:\path -Recurse -Filter "arquivo.txt"
💻 35. Agendar tarefa (cron / agendador)
🐂 GNU
crontab -e
✴️ PowerShell
# Exemplo simples para criar tarefa agendada via PowerShell
$action = New-ScheduledTaskAction -Execute "notepad.exe"
$trigger = New-ScheduledTaskTrigger -At 9am -Daily
Register-ScheduledTask -TaskName "AbrirNotepad" -Action $action -Trigger $trigger
💻 36. Limpar tela
🐂 GNU
clear
✴️ PowerShell
Clear-Host
💻 37. Mostrar variáveis do sistema (com nome e valor)
🐂 GNU
env
✴️ PowerShell
Get-ChildItem Env:
💻 38. Comparar arquivos linha a linha
🐂 GNU
diff file1 file2
✴️ PowerShell
Compare-Object (Get-Content file1) (Get-Content file2)
💻 39. Executar script local (bash / powershell)
🐂 GNU
./script.sh
✴️ PowerShell
.\script.ps1
💻 40. Parar execução do comando (Ctrl + C)
🐂 GNU
Ctrl + C
✴️ PowerShell
Ctrl + C
💻 41. Obter histórico de comandos na sessão atual
🐂 GNU
history
✴️ PowerShell
Get-History
💻 42. Obter arquivo com histórico de comandos
🐂 GNU
cat ~/.bash_history
✴️ PowerShell
Get-Content (Get-PSReadlineOption).HistorySavePath
💻 43. Buscar texto no histórico de comandos
🐂 GNU
history | grep termo
✴️ PowerShell
Get-History | Where-Object CommandLine -Match "termo"
💻 44. Exibir variáveis definidas na sessão atual
🐂 GNU
set
✴️ PowerShell
Get-Variable
💻 45. Definir variável local (shell/session)
🐂 GNU
VARIAVEL=valor
✴️ PowerShell
$VARIAVEL = "valor"
💻 46. Limitar saída de comando (paginador)
🐂 GNU
command | less
✴️ PowerShell
command | Out-Host -Paging
💻 47. Definir alias (apelido para comando)
🐂 GNU
alias ll='ls -la'
✴️ PowerShell
Set-Alias ll Get-ChildItem
💻 48. Remover alias
🐂 GNU
unalias ll
✴️ PowerShell
Remove-Item Alias:ll
💻 49. Mostrar informações da CPU
🐂 GNU
lscpu
✴️ PowerShell
Get-CimInstance Win32_Processor | Select-Object Name,NumberOfCores,NumberOfLogicalProcessors
💻 50. Abrir editor de texto no terminal
🐂 GNU
vim arquivo.txt
✴️ PowerShell
notepad arquivo.txt
🍖 Bônus:
Fazer download de arquivo:
- GNU:
wget https://url.com/file.zip
# Ou: wget https://url.com/file.zip -O outronome.zip
- PowerShell:
Invoke-WebRequest -Uri "https://url.com/file.zip" -OutFile "file.zip"
SOCIAL SHARE CARD GENERATOR