GNU/Linux >> Belajar Linux >  >> Linux

Cara Menginstal Windows PowerShell Core 6.0 di Linux

PowerShell adalah terdistribusi, scalable, konfigurasi heterogen, dan kerangka otomatisasi, yang terdiri dari shell baris perintah interaktif dan bahasa scripting, untuk sistem operasi Windows. Itu dibangun di atas .NET framework, dan Ini memungkinkan pengguna untuk mengotomatisasi dan menyederhanakan tugas sistem. Untuk detail lebih lanjut tentang PowerShell, lihat tautan berikut.

Dalam tutorial singkat ini, mari kita lihat cara menginstal PowerShell di Ubuntu 14.04/16.04/18.04 LTS dan CentOS 7 edisi server 64-bit.

Instal Windows PowerShell Core 6.0 di Linux

PowerShell dapat diinstal pada banyak distribusi Linux populer termasuk Arch Linux, Debian, Ubuntu, Fedora, CentOS, SUSE. Di sini saya telah menyertakan petunjuk instalasi untuk Debian, Ubuntu dan CentOS.

Di Ubuntu 14.04 LTS:

Unduh dan daftarkan kunci GPG Repositori PowerShell:

$ wget -q https://packages.microsoft.com/config/ubuntu/14.04/packages-microsoft-prod.deb
$ sudo dpkg -i packages-microsoft-prod.deb

Perbarui daftar sumber perangkat lunak:

$ sudo apt-get update

Kemudian, instal PowerShell menggunakan perintah:

$ sudo apt-get install -y powershell

Di Ubuntu 16.04 LTS:

Tambahkan kunci GPG Repositori PowerShell:

$ wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
$ sudo dpkg -i packages-microsoft-prod.deb

Perbarui daftar sumber perangkat lunak:

$ sudo apt-get update

Kemudian, instal PowerShell menggunakan perintah:

$ sudo apt-get install -y powershell

Di Ubuntu 18.04 LTS:

Daftarkan kunci GPG repositori PowerShell:

$ wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
$ sudo dpkg -i packages-microsoft-prod.deb

Perbarui daftar repositori dan instal PowerShell:

$ sudo apt-get update
$ sudo apt-get install -y powershell

Di Debian 8:

$ sudo apt-get install curl apt-transport-https
$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-jessie-prod jessie main" > /etc/apt/sources.list.d/microsoft.list'
$ sudo apt-get update
$ sudo apt-get install -y powershell

Di Debian 9:

$ sudo apt-get install curl gnupg apt-transport-https
$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/microsoft.list'
$ sudo apt-get update
$ sudo apt-get install -y powershell

Di CentOS 7

Tambahkan repositori PowerShell sebagai root pengguna:

# curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo

Instal PowerShell:

# yum install -y powershell

Untuk distribusi lain, silakan lihat petunjuk pemasangan resmi .

Kami sekarang telah menginstal PowerShell. Selanjutnya, kita akan melihat bagaimana menggunakannya secara real time.

Memulai PowerShell

Harap diperhatikan bahwa PowerShell untuk Linux masih dalam tahap pengembangan, sehingga Anda mengalami beberapa bug. Jika ada bug, bergabunglah dengan blog komunitas PowerShell (Tautan diberikan di akhir artikel ini) dan dapatkan bantuan.

Setelah Anda menginstal PowerShell, jalankan perintah berikut untuk masuk ke konsol/sesi PowerShell.

pwsh

Inilah tampilan konsol PowerShell di server Ubuntu 18.04 LTS saya.

PowerShell 6.1.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /home/sk>

PowerShell

Dalam sesi PowerShell, kami menyebutkan perintah PowerShell sebagai cmdlet , dan kami menyebutkan tanda perintah PowerShell sebagai PS /> .

Bekerja di PowerShell hampir mirip dengan BASH. Saya menjalankan beberapa perintah Linux di PowerShell. Tampaknya hampir semua perintah Linux berfungsi di PowerShell. Juga, PowerShell memiliki serangkaian perintah (cmdlet) sendiri. Fitur fungsi TAB (pelengkapan otomatis) berfungsi seperti di BASH.

Hapus? Nah, Mari kita beri beberapa contoh.

Lihat versi PowerShell

Untuk melihat versi PowerShell, masukkan:

$PSVersionTable

Contoh keluaran:

Name                           Value
----                           -----
PSVersion                      6.1.2
PSEdition                      Core
GitCommitId                    6.1.2
OS                             Linux 4.15.0-45-generic #48-Ubuntu SMP Tue Jan ...
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Seperti yang Anda lihat pada output di atas, versi PowerShell adalah 6.1.2 .

Membuat file

Untuk membuat file baru, gunakan 'Item Baru' perintah seperti yang ditunjukkan di bawah ini.

New-Item ostechnix.txt

Contoh keluaran:

    Directory: /home/sk


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
------          2/11/19  10:28 AM              0 ostechnix.txt

atau cukup gunakan ">" seperti yang ditunjukkan di bawah ini:

"" > ostechnix.txt

Di sini, "" - menjelaskan bahwa file tersebut kosong. ostechnix.txt adalah nama filenya.

Untuk menambahkan beberapa konten dalam file, jalankan perintah berikut:

Set-Content ostechnix.txt -Value "Welcome to OSTechNix blog!"

Atau

"Welcome to OSTechNix blog!" > ostechnix.txt
Melihat konten file

Kami telah membuat beberapa file dari PowerShell. Bagaimana kita melihat isi dari file itu? Itu mudah.

Cukup gunakan 'Dapatkan-Konten' perintah untuk menampilkan konten file apa pun.

Get-Content <Path> <filename>

Contoh:

Get-Content ostechnix.txt

Contoh keluaran:

Welcome to OSTechNix blog!
Menghapus file

Untuk menghapus file atau item, gunakan 'Remove-Item' perintah seperti yang ditunjukkan di bawah ini.

Remove-Item ostechnix.txt

Mari kita verifikasi apakah item tersebut benar-benar telah dihapus menggunakan perintah:

Get-Content ostechnix.txt

Anda akan melihat output seperti di bawah ini.

Get-Content : Cannot find path '/home/sk/ostechnix.txt' because it does not exist.
At line:1 char:1
+ Get-Content ostechnix.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (/home/sk/ostechnix.txt:String) [Get-Content], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Atau Anda bisa menggunakan "ls" perintah untuk melihat apakah file tersebut ada atau tidak.

Melihat proses yang sedang berjalan

Untuk melihat daftar proses yang sedang berjalan, jalankan saja:

Get-Process

Contoh keluaran:

 NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName 
 ------ ----- ----- ------ -- -- ----------- 
 0 0.00 0.00 0.02 599 599 agetty 
 0 0.00 0.00 0.00 2385 385 anacron 
 0 0.00 0.00 0.00 257 0 ata_sff 
 0 0.00 0.00 0.07 556 556 auditd 
 0 0.00 0.00 0.03 578 578 avahi-daemon 
 0 0.00 0.00 0.00 590 578 avahi-daemon 
 0 0.00 0.00 0.05 2327 327 bash 
 0 0.00 0.00 0.00 19 0 bioset 
 0 0.00 0.00 0.00 352 0 bioset 
 0 0.00 0.00 0.00 360 0 bioset 
 0 0.00 0.00 0.35 597 597 crond 
 0 0.00 0.00 0.00 31 0 crypto 
 0 0.00 0.00 0.11 586 586 dbus-daemon 
 0 0.00 0.00 0.03 63 0 deferwq 
 0 0.00 0.01 0.93 585 585 firewalld 
 0 0.00 0.00 0.00 30 0 fsnotify_mark 
 0 0.00 0.00 0.00 43 0 ipv6_addrconf 
 0 0.00 0.00 0.02 94 0 kauditd 
 0 0.00 0.00 0.00 20 0 kblockd 
 0 0.00 0.00 0.00 14 0 kdevtmpfs 
 0 0.00 0.00 0.00 351 0 kdmflush 
 0 0.00 0.00 0.00 359 0 kdmflush 
 0 0.00 0.00 0.00 13 0 khelper 
 0 0.00 0.00 0.03 29 0 khugepaged 
 0 0.00 0.00 0.00 26 0 khungtaskd 
 0 0.00 0.00 0.00 18 0 kintegrityd 
 0 0.00 0.00 0.00 41 0 kmpath_rdacd 
 0 0.00 0.00 0.00 42 0 kpsmoused 
 0 0.00 0.00 0.00 28 0 ksmd 
 0 0.00 0.00 0.17 3 0 ksoftirqd/0 
 0 0.00 0.00 0.02 27 0 kswapd0 
 0 0.00 0.00 0.00 2 0 kthreadd 
 0 0.00 0.00 0.00 39 0 kthrotld 
 0 0.00 0.00 0.01 2313 0 kworker/0:0 
 0 0.00 0.00 0.04 2369 0 kworker/0:0H 
 0 0.00 0.00 0.00 2440 0 kworker/0:1 
 0 0.00 0.00 0.05 2312 0 kworker/0:2H 
 0 0.00 0.00 0.28 2376 0 kworker/0:3 
 0 0.00 0.00 0.25 6 0 kworker/u2:0 
 0 0.00 0.00 0.00 272 0 kworker/u2:2 
 0 0.00 0.00 0.01 473 473 lvmetad 
 0 0.00 0.00 0.02 2036 036 master 
 0 0.00 0.00 0.00 21 0 md 
 0 0.00 0.00 0.00 7 0 migration/0 
 0 0.00 0.00 0.00 15 0 netns 
 0 0.00 0.00 0.22 653 653 NetworkManager 
 0 0.00 0.00 0.00 16 0 perf 
 0 0.00 0.00 0.01 2071 036 pickup 
 0 0.00 0.00 0.05 799 799 polkitd 
 0 0.00 0.02 5.02 2401 327 powershell 
 0 0.00 0.00 0.00 2072 036 qmgr 
 0 0.00 0.00 0.00 8 0 rcu_bh 
 0 0.00 0.00 0.73 10 0 rcu_sched 
 0 0.00 0.00 0.00 9 0 rcuob/0 
 0 0.00 0.00 0.51 11 0 rcuos/0 
 0 0.00 0.00 0.06 582 582 rsyslogd 
 0 0.00 0.00 0.00 267 0 scsi_eh_0 
 0 0.00 0.00 0.00 271 0 scsi_eh_1 
 0 0.00 0.00 0.00 275 0 scsi_eh_2 
 0 0.00 0.00 0.00 269 0 scsi_tmf_0 
 0 0.00 0.00 0.00 273 0 scsi_tmf_1 
 0 0.00 0.00 0.00 277 0 scsi_tmf_2 
 0 0.00 0.00 0.03 1174 174 sshd 
 0 0.00 0.00 0.79 2322 322 sshd 
 0 0.00 0.00 1.68 1 1 systemd 
 0 0.00 0.00 0.24 453 453 systemd-journal 
 0 0.00 0.00 0.04 579 579 systemd-logind 
 0 0.00 0.00 0.19 481 481 systemd-udevd 
 0 0.00 0.00 0.54 1175 175 tuned 
 0 0.00 0.00 0.02 12 0 watchdog/0 
 0 0.00 0.00 0.01 798 798 wpa_supplicant 
 0 0.00 0.00 0.00 17 0 writeback 
 0 0.00 0.00 0.00 378 0 xfs_mru_cache 
 0 0.00 0.00 0.00 379 0 xfs-buf/dm-1 
 0 0.00 0.00 0.00 539 0 xfs-buf/sda1 
 0 0.00 0.00 0.00 382 0 xfs-cil/dm-1 
 0 0.00 0.00 0.00 542 0 xfs-cil/sda1 
 0 0.00 0.00 0.00 381 0 xfs-conv/dm-1 
 0 0.00 0.00 0.00 541 0 xfs-conv/sda1 
 0 0.00 0.00 0.00 380 0 xfs-data/dm-1 
 0 0.00 0.00 0.00 540 0 xfs-data/sda1 
 0 0.00 0.00 0.51 383 0 xfsaild/dm-1 
 0 0.00 0.00 0.00 543 0 xfsaild/sda1 
 0 0.00 0.00 0.00 377 0 xfsalloc

Perintah di atas akan menampilkan seluruh daftar proses yang berjalan di sistem Linux Anda.

Untuk melihat proses tertentu yang sedang berjalan, gunakan '-Name' pilihan dengan perintah di atas.

Misalnya, untuk melihat proses PowerShell, jalankan:

Get-Process -Name pwsh

Contoh keluaran:

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
      0     0.00      99.32       3.28    2575 398 pwsh
Melihat alias perintah

Apakah Anda terlalu malas untuk mengetik seluruh perintah? Cukup ketik beberapa kata dan tekan tombol tab, perintah akan dilengkapi secara otomatis atau daftar perintah yang disarankan akan ditampilkan, seperti di shell BASH Linux.

Atau, ada alias untuk beberapa perintah.

Misalnya, untuk menghapus layar, ketik: Clear-Host .

Atau Anda cukup mengetikkan alias dari perintah di atas 'cls' atau 'clear' untuk mengosongkan layar.

Untuk melihat daftar alias yang tersedia, jalankan:

Get-Alias

Berikut adalah daftar lengkap alias yang tersedia:

CommandType Name Version Source 
----------- ---- ------- ------ 
Alias ? -> Where-Object 
Alias % -> ForEach-Object 
Alias cd -> Set-Location 
Alias chdir -> Set-Location 
Alias clc -> Clear-Content 
Alias clear -> Clear-Host 
Alias clhy -> Clear-History 
Alias cli -> Clear-Item 
Alias clp -> Clear-ItemProperty 
Alias cls -> Clear-Host 
Alias clv -> Clear-Variable 
Alias cnsn -> Connect-PSSession 
Alias copy -> Copy-Item 
Alias cpi -> Copy-Item 
Alias cvpa -> Convert-Path 
Alias dbp -> Disable-PSBreakpoint 
Alias del -> Remove-Item 
Alias dir -> Get-ChildItem 
Alias dnsn -> Disconnect-PSSession 
Alias ebp -> Enable-PSBreakpoint 
Alias echo -> Write-Output 
Alias epal -> Export-Alias 
Alias epcsv -> Export-Csv 
Alias erase -> Remove-Item 
Alias etsn -> Enter-PSSession 
Alias exsn -> Exit-PSSession 
Alias fc -> Format-Custom 
Alias fhx -> Format-Hex 3.1.0.0 Microsoft.PowerShell.Utility 
Alias fl -> Format-List 
Alias foreach -> ForEach-Object 
Alias ft -> Format-Table 
Alias fw -> Format-Wide 
Alias gal -> Get-Alias 
Alias gbp -> Get-PSBreakpoint 
Alias gc -> Get-Content 
Alias gci -> Get-ChildItem 
Alias gcm -> Get-Command 
Alias gcs -> Get-PSCallStack 
Alias gdr -> Get-PSDrive 
Alias ghy -> Get-History 
Alias gi -> Get-Item 
Alias gin -> Get-ComputerInfo 3.1.0.0 Microsoft.PowerShell.Management 
Alias gjb -> Get-Job 
Alias gl -> Get-Location 
Alias gm -> Get-Member 
Alias gmo -> Get-Module 
Alias gp -> Get-ItemProperty 
Alias gps -> Get-Process 
Alias gpv -> Get-ItemPropertyValue 
Alias group -> Group-Object 
Alias gsn -> Get-PSSession 
Alias gsv -> Get-Service 
Alias gu -> Get-Unique 
Alias gv -> Get-Variable 
Alias h -> Get-History 
Alias history -> Get-History 
Alias icm -> Invoke-Command 
Alias iex -> Invoke-Expression 
Alias ihy -> Invoke-History 
Alias ii -> Invoke-Item 
Alias ipal -> Import-Alias 
Alias ipcsv -> Import-Csv 
Alias ipmo -> Import-Module 
Alias kill -> Stop-Process 
Alias md -> mkdir 
Alias measure -> Measure-Object 
Alias mi -> Move-Item 
Alias move -> Move-Item 
Alias mp -> Move-ItemProperty 
Alias nal -> New-Alias 
Alias ndr -> New-PSDrive 
Alias ni -> New-Item 
Alias nmo -> New-Module 
Alias nsn -> New-PSSession 
Alias nv -> New-Variable 
Alias oh -> Out-Host 
Alias popd -> Pop-Location 
Alias pushd -> Push-Location 
Alias pwd -> Get-Location 
Alias r -> Invoke-History 
Alias rbp -> Remove-PSBreakpoint 
Alias rcjb -> Receive-Job 
Alias rcsn -> Receive-PSSession 
Alias rd -> Remove-Item 
Alias rdr -> Remove-PSDrive 
Alias ren -> Rename-Item 
Alias ri -> Remove-Item 
Alias rjb -> Remove-Job 
Alias rmo -> Remove-Module 
Alias rni -> Rename-Item 
Alias rnp -> Rename-ItemProperty 
Alias rp -> Remove-ItemProperty 
Alias rsn -> Remove-PSSession 
Alias rv -> Remove-Variable 
Alias rvpa -> Resolve-Path 
Alias sajb -> Start-Job 
Alias sal -> Set-Alias 
Alias saps -> Start-Process 
Alias sasv -> Start-Service 
Alias sbp -> Set-PSBreakpoint 
Alias sc -> Set-Content 
Alias select -> Select-Object 
Alias set -> Set-Variable 
Alias si -> Set-Item 
Alias sl -> Set-Location 
Alias sls -> Select-String 
Alias sp -> Set-ItemProperty 
Alias spjb -> Stop-Job 
Alias spps -> Stop-Process 
Alias spsv -> Stop-Service 
Alias sv -> Set-Variable 
Alias type -> Get-Content 
Alias where -> Where-Object 
Alias wjb -> Wait-Job

Untuk melihat alias untuk perintah tertentu, ketik:

Get-Alias cls

Contoh keluaran:

CommandType Name Version Source 
----------- ---- ------- ------ 
Alias cls -> Clear-Host
Melihat daftar lengkap perintah yang tersedia

Untuk melihat daftar semua perintah PowerShell yang tersedia, jalankan:

Get-Command
Melihat bantuan

Tidak tahu apa yang akan dilakukan? Tidak masalah. Cukup ketik 'bantuan' untuk mendapatkan bantuan. Anda tidak perlu mencari di Internet.

Anda juga dapat menggunakan 'Dapatkan-Bantuan' perintah bersama dengan perintah powershell apa pun. Ini adalah sesuatu yang mirip dengan 'pria' perintah di Linux.

Misalnya, untuk menampilkan bagian bantuan dari perintah yang disebut "Hapus-Host", jalankan:

Get-Help Clear-Host

Contoh keluaran:

NAME
 Clear-Host
 
SYNOPSIS
 
 
SYNTAX
 Clear-Host [<CommonParameters>]
 
 
DESCRIPTION
 

RELATED LINKS
 https://go.microsoft.com/fwlink/?LinkID=225747

REMARKS
 To see the examples, type: "get-help Clear-Host -examples".
 For more information, type: "get-help Clear-Host -detailed".
 For technical information, type: "get-help Clear-Host -full".
 For online help, type: "get-help Clear-Host -online

Seperti yang Anda lihat di atas, 'Dapatkan-Bantuan' menampilkan bagian bantuan dari perintah PowerShell tertentu, seperti nama perintah, format sintaks, alias, dan keterangan, dll.

Untuk keluar dari konsol PowerShell, cukup ketik:

exit

Saya harap Anda mendapatkan ide dasar tentang cara menginstal PowerShell Core versi alpha di Linux (Ubuntu dan CentOS), dan penggunaan dasarnya.

Bacaan lebih lanjut:

  • PowerShell di GitHub
  • Memulai PowerShell dari Channel9 - Video tutorial
  • Halaman komunitas PowerShell
  • Saluran YouTube PowerShell

Bacaan terkait:

  • Instal Subsistem Windows Untuk Linux Dengan Satu Perintah

Linux
  1. Cara menginstal Python di Linux

  2. Cara menginstal Java di Linux

  3. Cara Menginstal Kalkulator Microsoft Windows di Linux

  1. Cara menginstal Linux dalam 3 langkah

  2. Cara Menginstal NodeJS Di Linux

  3. Cara Menginstal atau Menghapus Windows PowerShell di Ubuntu/Lubuntu Linux

  1. Cara Instal Windows 10 di VirtualBox di Linux

  2. Cara Menginstal Python 3 di Windows 10

  3. Bagaimana cara menginstal Kali Linux