本文章整理归纳了一些 Windows 中常用的命令,Windows 与 Linux 部分命令名称相同,但是 Windows 命令直观上来看更加长但是命令名称更加直观。
在下文中,Windows 以 powershell 示例,Linux以 Ubuntu 系统 Bash 示例
在Windows中一行执行多个命令
不同命令之间使用;
进行连接
mkdir build ; cd build
这样就可以创建并进入build
文件夹了
文件、目录操作
操作 | Windows (PowerShell) | Linux (Bash) |
---|
当前目录 | cd | cd |
列出文件 | dir / ls (PowerShell 支持) | ls |
创建文件夹 | mkdir 文件夹名 | mkdir 文件夹名 |
删除文件夹 | rmdir /s 文件夹名 | rm -r 文件夹名 |
删除文件 | del 文件名 / Remove-Item 文件名 | rm 文件名 |
拷贝文件 | copy / Copy-Item | cp |
移动文件 | move / Move-Item | mv |
查看文件内容 | type / Get-Content | cat |
创建文件 | new-Item file.txt -ItemType file 或"" > file.txt | touch file.txt |
创建带内容文件 | Set-Content hello.txt "Hello" | echo "Hello" > hello.txt |
追加内容 | echo Another line >> file.txt | echo "Another line" >> file.txt |
编辑文件 | notepad file.txt | nano/vim file.txt |
查找文件与内容
操作 | Windows | Linux |
---|
按名称查找文件 | PowerShell: Get-ChildItem -Recurse -Filter 文件名 | find . -name "文件名" |
按内容查找文件 | Select-String -Pattern "关键词" | grep "关键词" 文件名 |
查找文件中包含关键词的文件 | findstr /s /m "关键词" * | grep -rl "关键词" . |
创建或解压
操作 | Windows | Linux |
---|
创建 zip 文件 | Compress-Archive -Path .\folder -DestinationPath out.zip | zip -r out.zip folder |
解压 zip 文件 | Expand-Archive out.zip -DestinationPath folder | unzip out.zip |
解压 tar.gz 文件 | 需要 7-Zip 或 tar | tar -xzvf file.tar.gz |
软件管理
操作 | Windows | Linux |
---|
包管理 | winget install xxx 或 choco install xxx (需安装) | apt install 等 |
查看已安装包 | winget list | dpkg -l / apt list --installed |
系统/进程管理
操作 | Windows | Linux |
---|
查看进程 | tasklist / Get-Process | ps / top / htop |
结束进程 | taskkill /PID 1234 | kill 1234 |
查看IP | ipconfig | ifconfig 或 ip a |
查看端口 | netstat -an | netstat -an 或 ss -tuln |
启动服务 | net start 服务名 | systemctl start 服务名 |
停止服务 | net stop 服务名 | systemctl stop 服务名 |
网络相关操作
操作 | Windows | Linux |
---|
ping | ping www.google.com | ping www.google.com |
下载文件 | Invoke-WebRequest / curl | wget / curl |
DNS测试 | nslookup 域名 | nslookup 或 dig |
清屏操作
操作 | Windows | Linux |
---|
清屏 | cls /clear | clear |