PowerShell : インストール2026/06/19 |
|
Microsoft の PowerShell for Linux をインストールします。 |
|
| [1] | |
| [2] | Snap から PowerShell をインストールします。 |
|
root@dlp:~# snap install powershell --classic powershell 7.6.3 from Canonical✓ installed |
| [3] | PowerShell の起動と主な操作です。 |
|
# PowerShell 起動 root@dlp:~# pwsh PowerShell 7.6.3 PS /root> # コマンドレット一覧表示 (下例は頭 10 行のみ表示) # 全て表示する場合は単に Get-Command で OK PS /root> (Get-Command)[0..9] CommandType Name Version Source ----------- ---- ------- ------ Alias Get-PSResource -> 1.2.0 Microsoft.PowerShell.PSResourceGet Function cd.. Function cd\ Function cd~ Function Clear-Host Function Compress-Archive 1.2.5 Microsoft.PowerShell.Archive Function exec Function Expand-Archive 1.2.5 Microsoft.PowerShell.Archive Function Find-Command 2.2.5 PowerShellGet Function Find-DSCResource 2.2.5 PowerShellGet # カレント PATH 表示 PS /root> pwd Path ---- /root # /home へ移動 PS /root> cd /home # 引数なしでホームディレクトリに戻る PS /home> cd # カレントディレクトリのファイル一覧を表示 (Get-ChildItem でも dir と同じ) PS /root> dir | ft -AutoSize -Wrap Directory: /root UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- drwx------ root root 06/19/2026 01:09 4096 snap -rw-r--r-- root root 03/30/2026 20:15 10319484 usermin-current.deb -rw-r--r-- root root 05/11/2026 03:16 27680572 webmin-current.deb # / のファイル一覧を表示 PS /root> Get-ChildItem / | ft -AutoSize -Wrap Directory: / UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- lrwxrwxrwx root root 04/20/2026 08:46 7 bin -> usr/bin drwxr-xr-x root root 05/06/2026 02:52 4096 boot dr-xr-xr-x root root 04/20/2026 18:23 4096 cdrom drwxr-xr-x root root 06/19/2026 00:40 3980 dev drwxr-xr-x root root 06/19/2026 00:53 4096 etc drwxr-xr-x root root 05/06/2026 02:45 4096 home ..... ..... # カレントディレクトリにファイル新規作成 PS /root> New-Item -Path test.txt Directory: /root UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- -rw-r--r-- root root 06/19/2026 01:11 0 test.txt PS /root> dir | ft -AutoSize -Wrap Directory: /root UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- drwx------ root root 06/19/2026 01:09 4096 snap -rw-r--r-- root root 06/19/2026 01:11 0 test.txt -rw-r--r-- root root 03/30/2026 20:15 10319484 usermin-current.deb -rw-r--r-- root root 05/11/2026 03:16 27680572 webmin-current.deb # カレントディレクトリにディレクトリ新規作成 PS /root> New-Item -ItemType Directory -Path testdir Directory: /root UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- drwxr-xr-x root root 06/19/2026 01:12 4096 testdir PS /root> dir | ft -AutoSize -Wrap Directory: /root UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- drwx------ root root 06/19/2026 01:09 4096 snap drwxr-xr-x root root 06/19/2026 01:12 4096 testdir -rw-r--r-- root root 06/19/2026 01:11 0 test.txt -rw-r--r-- root root 03/30/2026 20:15 10319484 usermin-current.deb -rw-r--r-- root root 05/11/2026 03:16 27680572 webmin-current.deb # echo してファイルにリダイレクト PS /root> echo "test content" >> test.txt # ファイルの内容を表示 PS /root> Get-Content test.txt test content # ファイルを移動/リネームする PS /root> Move-Item test.txt test1.txt PS /root> dir | ft -AutoSize -Wrap Directory: /root UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- drwx------ root root 06/19/2026 01:09 4096 snap drwxr-xr-x root root 06/19/2026 01:12 4096 testdir -rw-r--r-- root root 06/19/2026 01:12 13 test1.txt -rw-r--r-- root root 03/30/2026 20:15 10319484 usermin-current.deb -rw-r--r-- root root 05/11/2026 03:16 27680572 webmin-current.deb # ファイルをコピーする PS /root> Copy-Item test1.txt test2.txt PS /root> dir | ft -AutoSize -Wrap Directory: /root UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- drwx------ root root 06/19/2026 01:09 4096 snap drwxr-xr-x root root 06/19/2026 01:12 4096 testdir -rw-r--r-- root root 06/19/2026 01:12 13 test1.txt -rw-r--r-- root root 06/19/2026 01:12 13 test2.txt -rw-r--r-- root root 03/30/2026 20:15 10319484 usermin-current.deb -rw-r--r-- root root 05/11/2026 03:16 27680572 webmin-current.deb # ディレクトリを中身も含めて再帰的にコピーする PS /root> Copy-Item testdir testdir2 -Recurse PS /root> dir | ft -AutoSize -Wrap Directory: /root UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- drwx------ root root 06/19/2026 01:09 4096 snap drwxr-xr-x root root 06/19/2026 01:12 4096 testdir drwxr-xr-x root root 06/19/2026 01:14 4096 testdir2 -rw-r--r-- root root 06/19/2026 01:12 13 test1.txt -rw-r--r-- root root 06/19/2026 01:12 13 test2.txt -rw-r--r-- root root 03/30/2026 20:15 10319484 usermin-current.deb -rw-r--r-- root root 05/11/2026 03:16 27680572 webmin-current.deb # ファイルを削除する PS /root> Remove-Item test2.txt PS /root> dir | ft -AutoSize -Wrap Directory: /root UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- drwx------ root root 06/19/2026 01:09 4096 snap drwxr-xr-x root root 06/19/2026 01:12 4096 testdir drwxr-xr-x root root 06/19/2026 01:14 4096 testdir2 -rw-r--r-- root root 06/19/2026 01:12 13 test1.txt -rw-r--r-- root root 03/30/2026 20:15 10319484 usermin-current.deb -rw-r--r-- root root 05/11/2026 03:16 27680572 webmin-current.deb # ディレクトリを中身を含めて削除する PS /root> Remove-Item testdir2 -Recurse PS /root> dir | ft -AutoSize -Wrap Directory: /root UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- drwx------ root root 06/19/2026 01:09 4096 snap drwxr-xr-x root root 06/19/2026 01:12 4096 testdir -rw-r--r-- root root 06/19/2026 01:12 13 test1.txt -rw-r--r-- root root 03/30/2026 20:15 10319484 usermin-current.deb -rw-r--r-- root root 05/11/2026 03:16 27680572 webmin-current.deb # カレントディレクトリ配下から拡張子 .txt のファイルを検索する PS /root> Get-ChildItem "*.txt" -Recurse Directory: /root UnixMode User Group LastWriteTime Size Name -------- ---- ----- ------------- ---- ---- -rw-r--r-- root root 06/19/2026 01:12 13 test1.txt # test1.txt から "test" 文字列を検索する PS /root> Select-String -Pattern "test" test1.txt test1.txt:1:test content # 引数に指定したコマンドレットのヘルプを表示する PS /root> Get-Help Get-Content NAME Get-Content SYNTAX Get-Content [-Path] <string[]> [-ReadCount <long>] [-TotalCount <long>] [-Tail <int>] [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-Force] [-Credential <pscredential>] [-Delimiter <string>] [-Wait] [-Raw] [-Encoding <Encoding>] [-AsByteStream] [<CommonParameters>] ..... ..... |
|
|