-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# String | ||
|
||
# Native String | ||
## Native String | ||
|
||
Strings in bash can be native without any quote. | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
39 changes: 39 additions & 0 deletions
39
docs/document/Powershell/docs/File System/2.Working Directory.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Working Directory | ||
|
||
## Change Directory | ||
|
||
```ps1 | ||
Set-Location <path> | ||
``` | ||
|
||
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 | ||
``` |
59 changes: 59 additions & 0 deletions
59
docs/document/Powershell/docs/File System/3.Create Item.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <file_path> | ||
# or | ||
New-Item <file_path> | ||
``` | ||
|
||
> [!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 <dir_path> -ItemType Directory | ||
``` | ||
Powershell has another builtin function called `mkdir`, it's a shorthand for `New-Item <dir_path> -ItemType Directory` | ||
|
||
```ps1 | ||
mkdir <dir_path> | ||
``` | ||
|
||
> [!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 <symlink_path> -Target <source> -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` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |