
No mundo da automação de tarefas, dominar a linha de comando é uma habilidade essencial. Seja com os tradicionais comandos GNU, ou no ecossistema Windows, com o poderoso PowerShell, conhecer as ferramentas certas pode transformar sua produtividade.
Nesta postagem, vamos confrontar 50 comandos GNU com seus equivalentes no PowerShell.
rm -rf /home/$USER/folderRemove-Item -Path "C:\folder" -Recurse -Forceps aux | grep apache2 # httpdsystemd:
systemctl status apache2
Get-Service | Where-Object { $_.DisplayName -like "*Apache*" }sudo kill -9 $(pidof apache2) # httpdsystemd:
sudo systemctl stop apache2
Stop-Service -Name "Apache2.4"unset NOME_DA_VARIAVELC:\App\bin# Obtenha o valor atual da variável de ambiente Path do sistema
$envPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine)
# Separe os caminhos em um array
$paths = $envPath -split ';'
# Filtre para remover o caminho que você não quer mais
$newPaths = $paths | Where-Object { $_ -ne "C:\App\bin" }
# Recrie a variável de ambiente Path (sem o caminho indesejado)
$newPathString = ($newPaths -join ';').TrimEnd(';')
# Atualize a variável de ambiente do sistema
[Environment]::SetEnvironmentVariable("Path", $newPathString, [EnvironmentVariableTarget]::Machine)which mycommandGet-Command mycommandmkdir my-projectNew-Item -ItemType Directory "MyProject"mkdir -p my-project/folder/newNew-Item -Path "C:/MyProject/folder/new" -ItemType Directorymv folder new/path/Move-Item -Path "folder" -Destination "C:\new\path\"cd pasta/Set-Location pastacp file path/to/dest
cp -r folder/ path/to/destCopy-Item file path\to\dest
Copy-Item folder\ -Recurse -Destination path\to\dest$HOME
# echo $HOME
$USER
# echo $USER$env:USERPROFILE
# Write-Host $env:USERPROFILE
$env:USERNAME
# Write-Host $env:USERNAMEls -laGet-ChildItem -Forcecat file.txtGet-Content file.txtgrep "termo" file.txtSelect-String -Pattern "termo" -Path file.txtdf -hGet-PSDrive -PSProvider FileSystemfree -hGet-CimInstance Win32_OperatingSystem | Select-Object TotalVisibleMemorySize,FreePhysicalMemoryprintenvGet-ChildItem Env:mv oldname newnameRename-Item -Path oldname -NewName newnamesudo comandoStart-Process powershell -Verb runAsip addr showGet-NetIPAddressExemplo para Terlang:
C:\Program Files\Terlang\bin(Windows) e${HOME}/.local/terlang/bin/(GNU)
export PATH="${PATH}:${HOME}/.local/terlang/bin/"[System.Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Terlang\bin", [System.EnvironmentVariableTarget]::Machine)tail -n 20 file.logGet-Content file.log -Tail 20topGet-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)
pkill -f processoGet-Process -Name processo | Stop-Process -Forcetail -f file.logGet-Content file.log -Wait
tar -czvf archive.tar.gz folder/Compress-Archive -Path folder\* -DestinationPath archive.zipunzip archive.zipExpand-Archive -Path archive.zip -DestinationPath destino\echo $VARIAVEL$env:VARIAVELexport VARIAVEL=valor$env:VARIAVEL="valor"uname -aGet-CimInstance Win32_OperatingSystem | Select-Object Caption, Version, OSArchitecturedateGet-Datewhoquery usersudo netstat -tulpnGet-NetTCPConnection | Select-Object LocalAddress,LocalPort,OwningProcessfind /path -name "arquivo.txt"Get-ChildItem -Path C:\path -Recurse -Filter "arquivo.txt"crontab -e# 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 $triggerclearClear-HostenvGet-ChildItem Env:diff file1 file2Compare-Object (Get-Content file1) (Get-Content file2)./script.sh.\script.ps1Ctrl + CCtrl + ChistoryGet-Historycat ~/.bash_historyGet-Content (Get-PSReadlineOption).HistorySavePathhistory | grep termoGet-History | Where-Object CommandLine -Match "termo"setGet-VariableVARIAVEL=valor$VARIAVEL = "valor"command | lesscommand | Out-Host -Pagingalias ll='ls -la'Set-Alias ll Get-ChildItemunalias llRemove-Item Alias:lllscpuGet-CimInstance Win32_Processor | Select-Object Name,NumberOfCores,NumberOfLogicalProcessorsvim arquivo.txtnotepad arquivo.txtFazer download de arquivo:
wget https://url.com/file.zip
# Ou: wget https://url.com/file.zip -O outronome.zipInvoke-WebRequest -Uri "https://url.com/file.zip" -OutFile "file.zip"