SSH Command in Windows with examples

Shell basics and scripting commands in Windows

Small commands that make the window faster, and the first steps of scripts.

#echo

Print text

Syntaxecho text
  • echo HelloCMD

    Print a line

  • echo %USERNAME%CMD

    Print a variable in CMD

  • echo New line >> notes.txtCMD

    Append to a file

  • Write-Output "Hello $env:USERNAME"PowerShell

    PowerShell

#help / Get-Help

Read the help

Syntaxhelp [command]
  • helpCMD

    List built-in commands

  • dir /?CMD

    Help for one command

  • Get-Help Get-ChildItem -ExamplesPowerShell

    Examples for a PowerShell command

  • Get-Command *service*PowerShell

    Find commands by word

#cls

Clear the screen

Syntaxcls
  • clsCMD

    Clear CMD (PowerShell also accepts cls or Clear-Host)

#doskey / Set-Alias

Make a shortcut

Syntaxdoskey name=command $*
  • doskey ll=dir /a $*CMD

    Now ll lists everything (this window only)

  • Set-Alias ll Get-ChildItemPowerShell

    PowerShell alias

#redirects and pipes

Connect commands

Syntax> >> | 2>
  • dir > list.txtCMD

    Write output to a file (replaces it)

  • dir >> list.txtCMD

    Append instead

  • command 2> errors.txtCMD

    Save only error messages

  • ipconfig | findstr IPv4CMD

    Pipe one command into another

#Batch files

Your first script

Syntaxname.bat
  • notepad hello.batCMD

    Create a file with @echo off on line 1 and echo Hello on line 2

  • hello.batCMD

    Run it

  • for %f in (*.jpg) do echo %fCMD

    Do something for every jpg (inside a .bat file use %%f)

#PowerShell scripts

Your first PowerShell script

Syntaxname.ps1
  • Set-ExecutionPolicy -Scope CurrentUser RemoteSignedPowerShell

    Allow your own scripts to run

  • foreach ($f in Get-ChildItem *.jpg) { $f.Name }PowerShell

    Loop over files

  • .\hello.ps1PowerShell

    Run a script in the current folder

#if / goto

Tests and jumps

Syntaxif exist file command
  • if exist notes.txt echo yesCMD

    Test for a file

  • if "%1"=="" echo Missing argumentCMD

    Test an argument in a script

#timeout

Wait

Syntaxtimeout /t seconds
  • timeout /t 10CMD

    Wait ten seconds

  • Start-Sleep -Seconds 10PowerShell

    PowerShell

#exit

Close the window or session

Syntaxexit
  • exitCMD

    Leave CMD, PowerShell or an SSH session

Run these commands with SSH Command

SSH Command is a desktop app for Mac, Windows and Linux that puts a real terminal, SFTP file panes, a sudo switch and a searchable Linux command finder in one window. Type what you want to do, and send the command to your server with one click.

Download free Linux commands with examples SFTP & FTP client