@cyysu
2017-10-23T12:25:03.000000Z
字数 3121
阅读 856
- 时间:2017年10月23日
- 作者:Kali
- 邮箱:cyysu.github.io@gmail.com/2869905223@qq.com/微信lwyx1413
- 版本:4.0
- 描述:我们这里的安装平台采用Linux,如果是windows平台可能都需要你来安装。
powershell系列教程
# 第一种方法 加入APT源,然后apt安装
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
sudo apt-get update
sudo apt-get install -y powershell
# 第二种方法 下载powershell deb包进行安装,这里推荐采用这个方式
大家到下面那这个网址自己去下载,然后按照deb包安装方式进行安装。
https://github.com/PowerShell/PowerShell/tree/master
# 这里建议大家执行的时候在英文路径下,目前这个对中文支持还不是很好。
mj@DZ:~/powershell$ powershell
PowerShell v6.0.0-beta.8
Copyright (C) Microsoft Corporation. All rights reserved.
PS /home/mj/powershell>
PS /home/mj/powershell> dir
PS /home/mj/powershell> touch 123.txt
PS /home/mj/powershell> dir
Directory: /home/mj/powershell
Mode LastWriteTime Length Name
---- ------------- ------ ----
------ 17/10/23 下午8:02 0 123.txt
PS /home/mj/powershell>
# 清除命令
可以使用Linux下的clear或者windows下的cls
# 获取时间命令
PS /home/mj/powershell> Get-Date
2017年10月23日星期一 下午8:03:47
# 获取系统开机时间
PS /home/mj/powershell> Get-Uptime
Days : 1
Hours : 16
Minutes : 55
Seconds : 9
Milliseconds : 0
Ticks : 1473090000000
TotalDays : 1.70496527777778
TotalHours : 40.9191666666667
TotalMinutes : 2455.15
TotalSeconds : 147309
TotalMilliseconds : 147309000
# 获取当前目录的两种方式
PS /home/mj/powershell> pwd
Path
----
/home/mj/powershell
PS /home/mj/powershell> Get-Location
Path
----
/home/mj/powershell
# 常见的创建删除命令啥的我推荐用Linux上的,毕竟我们很熟悉Linux上命令了。
rm rmdir mkdir touch cat ls cp 等等
# 如果想查看某个命令的使用信息如:
cpio --help
# 显示系统中所有的进程。
PS /home/mj/powershell> Get-Process
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
------ ----- ----- ------ -- -- -----------
0 0.00 2.04 0.00 2138 126 (sd-pam)
0 0.00 2.05 0.00 2745 743 (sd-pam)
0 0.00 7.66 2.73 1068 068 accounts-daemon
0 0.00 0.00 0.00 98 0 acpi_thermal_pm
# 如果我们想查看某一进程的详细信息
PS /home/mj/powershell> Get-Process systemd
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
------ ----- ----- ------ -- -- -----------
0 0.00 5.77 6.26 1 1 systemd
0 0.00 4.74 0.06 2126 126 systemd
0 0.00 4.83 0.05 2743 743 systemd
# 显示命令的帮助
PS /home/mj/powershell> Get-Help clear
NAME
Clear-Host
SYNOPSIS
Clears the display in the host program.
SYNTAX
Clear-Host [<CommonParameters>]
DESCRIPTION
The Clear-Host function removes all text from the current display, including commands and output that might have accumula
ted. When complete, it displays the command prompt. You can use the function name or its alias, CLS.
Clear-Host affects only the current display. It does not delete saved results or remove any items from the session. Sessi
on-specific items, such as variables and functions, are not affected by this function.
Because the behavior of the Clear-Host function is determined by the host program, Clear-Host might work differently in d
ifferent host programs.
# 查看所有命令
PS /home/mj/powershell> Get-Command
CommandType Name Version Source
----------- ---- ------- ------
Function Add-NodeKeys 0.0 PSDesiredStateConfiguration
Function AddDscResourceProperty 0.0 PSDesiredStateConfiguration
Function AddDscResourcePropertyFromMetadata 0.0 PSDesiredStateConfiguration
# 显示命令设置的别名
PS /home/mj/powershell> Get-Alias
CommandType Name Version Source
----------- ---- ------- ------
Alias ? -> Where-Object
Alias % -> ForEach-Object
# 给命令设置别名
PS /home/mj/powershell> Set-Alias
cmdlet Set-Alias at command pipeline position 1
Supply values for the following parameters:
Name:
支付宝 微信