diff --git a/docs/document/Bash/docs/Bash as A Language/String.md b/docs/document/Bash/docs/Bash as A Language/String.md index 1610c6b1..802bc878 100644 --- a/docs/document/Bash/docs/Bash as A Language/String.md +++ b/docs/document/Bash/docs/Bash as A Language/String.md @@ -1,6 +1,6 @@ # String -# Native String +## Native String Strings in bash can be native without any quote. diff --git a/docs/document/Powershell/docs/Overview.md b/docs/document/Powershell/docs/1.Overview.md similarity index 100% rename from docs/document/Powershell/docs/Overview.md rename to docs/document/Powershell/docs/1.Overview.md diff --git a/docs/document/Powershell/docs/Alias.md b/docs/document/Powershell/docs/Alias.md index a7ebaa89..ea817b3c 100644 --- a/docs/document/Powershell/docs/Alias.md +++ b/docs/document/Powershell/docs/Alias.md @@ -58,3 +58,6 @@ alias gl='git log' # fine New-Alias gl 'git log' # not allowed! # [!code error] ``` +> [!TIP] +> Use functions to do alias with predetermined parameters in your profile. + diff --git a/docs/document/Powershell/docs/File System/1.Overview.md b/docs/document/Powershell/docs/File System/1.Overview.md new file mode 100644 index 00000000..1b7605c1 --- /dev/null +++ b/docs/document/Powershell/docs/File System/1.Overview.md @@ -0,0 +1,9 @@ +# Overview + +**FileSystem** is a builtin **PSProvider** in Powershell. + +FileSystem can have one or more **PSDrive** depends on the system. + +In windows, drives can be `C:`, `D:` and so on. In linux they can be some mount points. + +This is introduces how to manipulate file system objects with item-related cmdlet. diff --git a/docs/document/Powershell/docs/File System/2.Working Directory.md b/docs/document/Powershell/docs/File System/2.Working Directory.md new file mode 100644 index 00000000..b5c9731b --- /dev/null +++ b/docs/document/Powershell/docs/File System/2.Working Directory.md @@ -0,0 +1,39 @@ +# Working Directory + +## Change Directory + +```ps1 +Set-Location +``` + +Powershell has three builtin aliases for `Set-Location` + +```console +$ Get-Alias -Definition 'Set-Location' + +CommandType Name Version Source +----------- ---- ------- ------ +Alias cd -> Set-Location +Alias chdir -> Set-Location +Alias sl -> Set-Location +``` + +## Current Working Directory + +There's two ways to get current working directory in Powershell. + +- `$PWD` builtin string variable. Refreshes on each time location changed. +- `Get-Location` cmdlet. Returns a `PathInfo` object. + - `pwd` is an builtin alias for `Get-Location`. + +```ps1 +(Get-Location).Path # equivelant to $pwd +``` + +```console +$ Get-Location | select -Property * + +Drive Provider ProviderPath Path +----- -------- ------------ ---- +D Microsoft.PowerShell.Core\FileSystem +``` diff --git a/docs/document/Powershell/docs/File System/3.Create Item.md b/docs/document/Powershell/docs/File System/3.Create Item.md new file mode 100644 index 00000000..4ba5b5d4 --- /dev/null +++ b/docs/document/Powershell/docs/File System/3.Create Item.md @@ -0,0 +1,59 @@ +# Create Item + +Powershell uses a single cmdlet named `New-Item` to represent all kinds of creation logic for file system items like folder, file, symlinks... + +> [!TIP] +> Use `ni` alias for `New-Item`. + +## File + +`New-Item` creates file without extra options by default. + +```ps1 +New-Item -Path +# or +New-Item +``` + +> [!NOTE] +> `-Path` is the first positional parameter which can be ignored. + +> [!NOTE] +> `-Path` is `string[]`, so you can create multiple items at a same time with same options. + +> [!TIP] +> Use `-Force` flag to overwrite existing target. + +## Directory + +```ps1 +New-Item -ItemType Directory +``` +Powershell has another builtin function called `mkdir`, it's a shorthand for `New-Item -ItemType Directory` + +```ps1 +mkdir +``` + +> [!NOTE] +> When creating directory, `New-Item` ensures necessary parent directories by default, so there's no things like `mkdir -p`. + +> [!TIP] +> Use `-Force` flag to overwrite existing target. + +## Symbolic Link + +```ps1 +New-Item -Target -ItemType SymbolicLink +``` + +> [!TIP] +> Use `-Force` flag to overwrite existing target. + +## Ignore Wildcards + +`-Path` translates wildcards by default, if you do need to include special characters from wildcards syntax for your new item, use `-LiteralPath`. + +```ps1 +New-Item -LiteralPath 'foo*.txt' # creates a file literally named `foo*.txt` +``` diff --git a/docs/document/Powershell/docs/PSDrive.md b/docs/document/Powershell/docs/PSDrive.md new file mode 100644 index 00000000..59c2bb5d --- /dev/null +++ b/docs/document/Powershell/docs/PSDrive.md @@ -0,0 +1,30 @@ +# PSProvider + +**PSProvider** is another confusing concept from powershell. +A PSProvider basically provides a way to browse and access items from a source. +There's some builtin PSProviders like `FileSystem`, `Registry` on windows and so on. + +You can check all available providers by: + +```console +$ Get-PSProvider + +Name Capabilities Drives +---- ------------ ------ +Registry ShouldProcess {HKLM, HKCU} +Alias ShouldProcess {Alias} +Environment ShouldProcess {Env} +FileSystem Filter, ShouldProcess, Credentials {C, D, Temp} +Function ShouldProcess {Function} +Variable ShouldProcess {Variable} +Certificate ShouldProcess {Cert} +WSMan Credentials {WSMan} +``` + +## PSDrive + +Each PSProvider can have one or more **PSDrive**. + +PSDrive is kind of like one of the entries of a PSProvider. + +Check all available PSDrive by `Get-PSDrive`.