- 1. Working directories
- 2. 紅樓夢 - 臺大開放式課程 (NTU OpenCourseWare)
- 3. 文具
- 4. Powershell/BASH
- 5. BASH和PowerShell命令对照表 5
- 5.1. 5 条评论 “BASH和PowerShell命令对照表”
Working directories
1 | i='/media/ht/ht_5T_9/YouTubes/Book_Reading/红楼梦'; cd ${i} |
紅樓夢 - 臺大開放式課程 (NTU OpenCourseWare)
1 | axel 'http://140.112.161.118/dl_video.php?fn=100S116_CT09V01.mp4' |
文具
- 打钉器 - Google Search
- 订书器 - 商品搜索 - 京东
- 可得优(KW-triO) 5990电动订书机智能感应全自动装订订书器订书机可订25页【图片 价格 品牌 报价】-京东
- 【国誉SLN-MSH110D】日本国誉(KOKUYO)学生办公便携式环保无针订书机 10枚装订 32121100mm 黑 SLN-MSH110D【行情 报价 价格 评测】-京东
- 日本国誉无针订书机压纹 MPH105 新型办公订书器 钉书机 可装订5枚纸 白色【图片 价格 品牌 报价】-京东
- 德国(MASTERPROOF)电动射钉机 打钉枪两用 码钉枪打钉机木工电动多用 电动气钉机射钉机 门钉直钉两用电动码钉枪+取钉器+收纳盒【图片 价格 品牌 报价】-京东
- 【勒塔LT-NG193】勒塔(LETA) 重型手动三用打钉枪(送门钉U型钉T钉各500枚)打钉机码钉机射钉器LT-NG193【行情 报价 价格 评测】-京东
Powershell/BASH
收集和分享 Windows PowerShell 相关教程,技术和最新动态
收集和分享 Windows PowerShell 相关教程,技术和最新动态
主菜单
首页 » Powershell » Powershell小技巧 » BASH和PowerShell命令对照表
BASH和PowerShell命令对照表 5
2016年12月5日 在 Powershell小技巧 来自 jailman
(adsbygoogle = window.adsbygoogle || []).push({});
ash | PowerShell | Description |
Scripting Basics | ||
Put a “shebang” at the beginning of the file: <br>#!/bin/bash Change permissions on script file to allow execution. |
Give the file a ps1 extension. For downloaded scripts, unblock the file under file properties in Windows Explorer. | Steps for making scripting files run. In PowerShell, the first time you do scripting, you will need to set the appropriate security settings: run PowerShell as administrator and type set-executionpolicy remotesigned . |
source (or) . |
. |
shell built-in: execute the commands in a file |
echo _String_ |
echo _String_ (or) Write-Host _String_ |
Prints String to the screen. In PowerShell, Write-Host forces the output to the screen instead of being a return value. |
_var_=0 (No spaces around =) |
$_var_ = 0 |
Creates a variable $var. In BASH, do not put whitespace around the equals sign, and do not use a $ in the variable assignment. |
let _var_=$_var_+5 (or) <br>_var_=$(( $_var_ + 5 )) |
$_var_ += 5 |
Add 5 to $var |
# _comment_ |
# _comment_ |
A comment |
Strings | ||
= != |
-eq -ne -ceq -cne |
String comparisons. In BASH, be sure the strings litereals are in quotes. |
"" | gm |
Get a list of non-static string members | |
[string] | gm -static |
Get a list of static string members | |
${_string_#_text_to_remove_} |
_string_.TrimStart("_characters_") |
Removes the specified characters/text from the beginning of the string. |
${_string_%_text_to_remove_} |
_string_.TrimEnd("_characters_") |
Removes the specified characters/text from the end of the string. Suppose $fnm == helloThere.txt; then ${fnm%.???} is helloThere |
Pattern Matching | ||
grep |
select-string |
print lines matching a pattern |
sed |
-replace |
performs string transformations |
Booleans and Conditions | ||
true false |
$true $false |
Boolean literals |
-lt -gt -le -ge -eq -ne |
-lt -gt -le -ge -eq -ne |
Arithmetic relational operators |
-like |
True if a string matches a wildcard pattern | |
-match |
True if a string matches a regular expressions | |
Where-Object { _condition_ } |
Used to filter input by a condition. Remember that $_ refers to the current object being tested. | |
-z $_var_ |
$_var_ -eq $null |
True if $var is null |
-n $_var_ |
$_var_ -ne $null |
True if $var is not null (contains one or more characters) |
-o -a |
-or -and |
Logical or and and |
-e _file_ |
Test-Path _file_ |
True if file exists. |
! -e _file_ |
! (Test-Path _file_) |
True if file does not exist. |
-d _file_ |
_file_.PSISContainer |
True if file is a directory. In PowerShell, if file is not a file variable, be sure to get the file object first with gi . |
-s _file_ |
True if file exists and has a size greater than zero. | |
_file1_ -nt _file2_ |
True if file1 is newer (according to modification date) than file2 | |
_file1_ -ot _file2_ |
True if file1 is older (according to modification date) than file2 | |
Control Structures | ||
if [ _condition_ ] <br>then <br>_codeblock_ <br>fi |
if (_condition_) { <br>_codeblock_ <br>} |
If statement. In BASH, be sure to leave a space between the condition and the bracket. |
if [ _condition_ ] <br>then <br>_codeblock_ <br>elif [ _condition_ ] <br>then <br>_codeblock_ <br>else <br>_codeblock_ <br>fi |
if (_condition_) { <br>_codeblock_ <br>} <br>elseif (_condition_) { <br>_codeblock_ <br>} <br>else { <br>_codeblock_ <br>} |
If – else if – else statement |
var=0 <br>while [ $var -lt 10 ] <br>do <br>echo $var <br>var=$(( $var + 1 )) <br>done |
$var = 0 <br>while ($var -lt 10) { <br>echo $var <br>$var++ <br>} |
Prints numbers 0 through 9. |
for ((i=0; i < 10; i++)) do <br>echo $i <br>done |
for ($i=0;$i -lt 10; $i++) <br>{ <br>echo $i <br>} |
Prints numbers 0 through 9. |
for _var_ in $_array_ <br>do <br>_codeblock_ <br>done |
foreach ($_var_ in $_array_) <br>{ <br>_codeblock_ <br>} |
For each loop |
continue break |
continue break |
Loop controls: continue stops current loop iteration and begins the next; break exits the loop currently being executed. |
basename _file_ |
_file_.name |
The name of file without the path. In PowerShell, remember to first get the file object. |
dirname _file_ |
_file_.directoryname |
The name directory file is in. In PowerShell, remember to first get the file object. |
stat -c%s $_file_ (or) $(stat -c%s $_file_) |
_file_.length |
The number of bytes in file. In PowerShell, remember to first get the file object. |
_file_.LastWriteTime |
The last modified time for file. Remember to first get the file object. | |
_files_=`ls` (or) _files_=$(ls) (or) _files_=* |
$_files_ = Get-Item * |
Store a list of the files in the current working directory in $files. In PowerShell, check out the -exclude flag as well as the Get-ChildItem cmdlet. |
| > >> 2> 2>> |
| > >> 2> 2>> |
Piping, output and error redirection. In BASH, output redirected to /dev/null is gone. In PowerShell, output redirected to $null is gone. |
_printArg_() <br>{ <br>_echo_ $1 <br>} |
function _printArg_ <br>{ <br>param ($_p1_) <br>_echo $p1_ <br>} |
function to print the first argument to the screen. |
_return_five_() <br>{ <br>return _5_ <br>}<br><br> _return_five_ <br>echo $? |
function _return_five_ <br>{ <br>echo _5_ (or) return _5_ <br>}<br><br> $_value_ = _return_five_ <br>echo $_value_ |
Function returns 5, which is printed after the function call. In PowerShell, any output in a function that is not caught is returned. The return statement merely ends the function. The return value of a BASH function is stored in the variable $?. |
File Information/Operations | ||
ls |
Listing of files. For bash, learn the options of -lisa, -r, -R . |
|
ls |
Listing of files. For PowerShell, learn -f, -r, -filter, and -exclude |
|
tree |
tree |
Graphically displays the directory structure of a drive or path. |
cat |
cat |
List the contents of a file on the stdout |
more |
more |
List the contents of a file on the stdout , pausing after each page |
mkdir |
mkdir |
Creates a directory. |
rmdir |
rmdir |
Deletes a folder if it is empty |
pwd |
pwd |
print working directory |
cd |
cd |
Change the current directory to the one given as argument. |
pushd |
pushd |
Saves the current directory name on the stack, and then cd’s the one given as argument. |
popd |
popd |
Pop off the top-most name on the stack, and then cd to it |
mv |
mv |
Moves or renames files. In PowerShell, check out the -force and -WhatIf flags. In BASH, check out the -f flag. |
cp -r |
cp -r |
Copies files and directory trees recursively. |
cp |
cp |
Copies files. In PowerShell, check out the -force and -WhatIf flags. In BASH, check out the -f flag. |
rm |
rm |
Deletes a file. Check out the -r flag. In PowerShell, check out the -force and -WhatIf flags. In BASH, check out the -f flag. |
cat |
cat |
show the contents of each file in sequence |
more |
more |
pagination |
rm |
rm |
Remove files |
ln |
Link (hard or soft) to an existing file. | |
mklink |
Link (hard or soft) to an existing file. Type cmd /c mklink to use it in PowerShell |
|
chmod |
attrib |
Change file permissions/attributes |
icacls |
Displays or modifies access control lists (ACLs) of files | |
chown |
icacls |
Change ownership of a file. In PowerShell, multiple steps are necessary |
umask |
get/set the file mode creation mask; packed vector of bits controlling the initial permissions on a newly created file | |
du |
measure |
Disk space Used. In PowerShell, try gci . -r | measure -property length -sum |
wc |
Measure-Object |
word count, etc. |
od |
Octal dump of file content. Almost always used with -x for hexadecimal dump | |
tr |
Translate/substitute characters; useful in improving interoperability | |
assoc |
List associations of commands with extensions. Type cmd /c assoc to use it in PowerShell |
|
file |
Heuristically determine the type of file content | |
grep |
select-string |
Search for a string in a file’s content. For now, learn it without regexp. |
find |
gci |
Locate a file. By name, etc. For now, learn it without regexp. |
which |
Gives the full path name of a command | |
where |
Gives the full path name of a command. Type cmd /c where to use it in PowerShell |
|
diff |
diff |
List the differences between two text files |
cmp, diff |
compare, diff |
show the differences between two files |
gci . -r | sort length -descending | select -first 10 |
get a list of the 10 largest files in the current directory (recursive) | |
vi |
vim |
A powerful text editor. For now, learn to edit simple text files with it. |
kate, leafpad |
notepad |
Simple text editors. |
emacs |
emacs |
A very powerful multi-purpose text editor. For now, learn to edit simple text files with it. |
Processes | ||
time |
Measure-Command |
times commands, etc. |
ps |
ps |
shows current processes |
gps | sort ws | select -last 5 |
Get a list of the 5 processes using the most memory | |
gsv | where {$_.Status -eq "Stopped"} |
Get a list of stopped services | |
top |
like ps, but with continuous updates | |
bg |
place a STOPped process in the background | |
fg |
bring a backgrounded process to foreground | |
kill |
kill |
kills a running program |
ltrace |
show lib calls made | |
strace |
show sys calls made | |
System | ||
man |
man |
show reference pages |
set |
set |
set the values of shell variables |
set |
gv |
get and show the values of shell variables |
env |
ls env:\ |
lists the current environment variables |
$PATH |
$env:path |
the search path |
links |
WWW/News/Mail browser | |
sftp, filezilla |
filezilla |
transfer files securely to/from a remote machine |
ssh, putty |
sshclient, putty |
remote login securely |
w |
who is on the system, and what they are doing | |
df |
gdr |
show mounted volumes, etc. |
原文链接: BASH and PowerShell Quick Reference
×用微信扫描并分享
本文链接: https://www.pstips.net/bash-and-powershell-quick-reference.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
暂时没有相关文章。
发表评论 取消回复
您的电子邮箱地址不会被公开。 必填项已用*标注
评论
显示名称 *
电子邮箱地址 *
网站地址
5 条评论 “BASH和PowerShell命令对照表”
-
Mooser Lee 2016年12月5日 于 下午 10:34
感谢jailman,个人觉得这个表格内容总结的很不错,就复制了过来。
等有时间了再把右边的描述列翻译过来。-
jailman 文章作者 2016年12月6日 于 上午 10:22
作为一名linux管理员有时使用powershell是有些无所适从的,因为一些命令用习惯了而powershell没有的话就需要gow,cygwin的辅助。
当然powershell依然是强大和值得推崇的。
-
-
jailman 文章作者 2016年12月6日 于 上午 10:09
赞!
-
Benben 2018年7月26日 于 下午 4:52
谢谢分享, MARK
-
winds 2019年8月27日 于 上午 10:28
谢谢,这表太好了,一目了然的语法区别和说明.
文章导航
· © 2021 PowerShell 中文博客 · [沪ICP备14006567号] ·
/* <![CDATA[ / var viewsCacheL10n = {“admin_ajax_url”:”https:\/\/www.pstips.net\\/wp-admin\\/admin-ajax.php","post_id":"6009"}; / ]]> */