Skip to content

什么是 PowerShell?

Windows PowerShell 是一种易于使用的命令行 Shell 和脚本环境,用于自动执行基于 Windows 的系统的管理任务。 Windows PowerShell 预安装在 Windows 操作系统的所有新式版本上。

Useful Terminal Commands

In Windows, we assume that PowerShell v7 has been installed. While with Linux and macOS, the commands in the table below are just listed for comparison purposes. Just note the differences.

Windows CommandsDescriptionLinux + macOS
pwdor gl or Get-LocationPrint the path of the current directory
mkdir FOLDERPATHCreate a new directory
ni FILEPATHCreate a new filetouch FILEPATH
clearClear the terminal window
lsList the contents of a folder
ls -alList all the contents of a folder with info
cat TARGETShow the content of TARGET
cd FOLDERPATHChange into a directory
cd ..Change into the parent directory
echo TEXTPrint TEXT to the terminal
echo TEXT > TARGETPrint TEXT to a file named TARGET
echo TEXT >> TARGETAppend TEXT to TARGET
cp SOURCE TARGETCopy SOURCE to TARGET
rni SOURCE TARGETRename SOURCE to TARGETmv SOURCE TARGET
python PYTHONFILERun PYTHONFILE

Note: Remane or move SOURCE to TARGET in Linux and MacOS.

To see a full list of PowerShell commands versus aliases, run Get-Alias | ConvertTo-Html | Out-File aliases.html and Invoke-Item aliases.html to view the file in a browser.

Configuration

To change your theme, adjust the init script in C:\Users\Alowr\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

Example:

ps1
oh-my-posh init pwsh --config 'C:\Users\Alowr\AppData\Local\Programs\oh-my-posh\themes\jandedobbeleer.omp.json' | Invoke-Expression

Custom configuration

You can export the current theme (default, or set via --config) to the format you like (json, yaml, or toml) which can be used to tweak and store as your own custom configuration.

ps
oh-my-posh config export --output $env:POSH_THEMES_PATH/.mytheme.omp.json

This will create your configuration file in path C:\Users\Alowr\AppData\Local\Programs\oh-my-posh\themes\.mytheme.omp.json

In case you want to enable auto-upgrades, you need to edit your configuration file, by adding the following line to your configuration file.

json
{
  "auto_upgrade": true
}

Learning Paths

  1. Learn PowerShell in a Month of Lunches, Fourth Eidition

    • Before you begin
    • Meet PowerShell
    • Using the help system
    • Running commands
    • Working with providers
    • The pipeline: Connecting commands
    • Adding commands
    • Objects: Data by another name
    • A practical interlude
    • The pipeline, deeper
    • Formatting: And why it’s done on the right
    • Filtering and comparisons
    • Remote control: One-to-one and one-to-many
    • Multitasking with background iobs
    • Working with many objects, one at a time
    • Variables: A place to store your stuff
    • Input and output
    • Sessions: Remote control with less work
    • You call this scripting?
    • Improving your parameterized script
    • Using regular expressions to parse text files
    • Using someone else’s script
    • Adding logic and loops
    • Handling errors
    • Debugging techniques
    • Tips, tricks,and techniques
    • Never the end