在 Windows 中,您可以使用命令提示符(use the Command Prompt)和Windows PowerShell控制台来更好地控制和更快地管理操作系统。这两种CLI(CLIs)(命令行解释器)还可以帮助您解决 PC 的严重问题(troubleshoot serious issues with your PC)。
Mac 的终端(Terminal)也是如此,但它基于 UNIX 的性质要求您输入一组不同的命令。
如果您最近切换到使用Mac,您将学习终端(Terminal)等效于以下 15 个有用的命令提示符(Command Prompt)和Windows PowerShell命令。
1.查看系统信息
假设(Suppose)您要识别计算机上的各种硬件和软件组件(处理器、RAM、操作系统版本等)。在这种情况下,您可以使用systeminfo命令在(systeminfo )命令提示符(Command Prompt)或Windows PowerShell中查看信息。
在Terminal中,改为执行以下命令:
system_profiler
您还可以提示终端(Terminal)按数据类型过滤信息。例如,您只能通过将SPHardwareDataType附加到命令末尾来获得 Mac 硬件的概览——例如system_profiler SPHardwareDataType。
有关数据类型的列表,请运行system_profiler -listDataTypes命令。
要通过Mac上的(Mac)GUI(图形用户界面)查看信息,请按住Option键并转到Apple菜单 >系统信息(System Information)。
2. Ping 设备和网络
您可以通过命令提示符(Command Prompt)或Windows PowerShell运行(Windows PowerShell)ping <host>命令来诊断网站和本地设备的连接问题。这会提示您的 PC 发送和接收数据包,并且您可以发现响应时间和数据包丢失方面的异常情况。
ping <host> 命令对大多数CLI(CLIs)都是通用的,但终端(Terminal)不会设置 ping 计数,除非您使用-c参数执行它,如下所示:
ping -c <count> <host>
3.检查网络配置
在 PC 上,通过命令提示符运行(Command Prompt)ipconfig会加载Internet 协议配置(Internet Protocol Configuration)实用程序。它允许您识别TCP/IP网络配置以及有关 IP 地址、子网掩码、默认网关等的信息。
终端(Terminal)等效项打开接口配置(Interface Configuration)并使用以下命令:
如果配置(ifconfig)
默认情况下,ifconfig 仅显示活动网络。要使其显示所有接口,请运行ifconfig -a。
4.刷新DNS缓存
计算机上过时的域名系统 (DNS)(Domain Name System (DNS))缓存会导致与网站的连接问题。在Windows中,通过提升的命令提示符(Command Prompt)控制台运行ipconfig /flushdns清除计算机的本地 DNS 缓存(clear your computer’s local DNS cache)。
Mac上相当于清除DNS缓存的终端(Terminal)如下:
sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder
您必须输入管理员密码才能授权该命令。
5.查看所有正在运行的进程
与Windows 任务管理器(Windows Task Manager)相比,在命令提示符(Command Prompt)或Windows PowerShell中键入tasklist可以更清晰地查看 PC 的后台进程。它还包含每个任务的进程ID(IDs) ( PID ) 和内存使用统计信息等信息。(PIDs)
在Mac上,您可以运行以下两个命令之一:
top命令实时显示资源最密集的进程列表,而ps -ax(ps -ax)显示Mac上的完整任务列表。
6.结束进程
您还可以使用命令提示符(Command Prompt)和Windows PowerShell通过(Windows PowerShell)taskkill <PID> 命令 结束正在运行的进程。
Mac 的终端等效项是:
kill <PID>
此外,您可以使用killall <process name>命令结束所有包含特定名称的Mac进程,例如(Mac)Garageband。这是使用 Terminal 关闭 Mac 进程(shutting down Mac processes using Terminal)的完整指南。
7.检查网络统计
Windows中的netstat命令可让您查看所有活动TCP连接的列表并帮助识别与网络相关的问题(identify network-related problems)。
在Mac上,运行相同的命令会产生类似的结果:
网络统计(netstat)
要查看特定于终端(Terminal)的标志和选项列表,请键入man netstat。
8.修复磁盘错误
Windows上的Check Disk 命令行实用程序可以通过在命令提示符(Command Prompt)或Windows PowerShell中运行chkdsk来调用,它允许您检查和修复与磁盘相关的错误。
macOS 中的终端(Terminal)等效项是fsck(文件系统一致性检查)命令。首先(Start)以单用户模式启动您的Mac —在启动时按Command + S。然后,运行以下命令:
/sbin/fsck -fy
9. 创建符号链接
如果您发现无法更改应用程序和程序用于存储文件的位置,则符号链接(符号链接)至关重要。
例如,您可以使用符号链接将任何文件夹同步到云存储服务,方法是使其看起来好像位于默认同步目录中。在Windows上,您使用mklink /J 命令。
在 macOS 上,终端(Terminal)等效项是:
In -s <original folder path> <target folder path>
要了解更多信息,请查看符号链接在 Mac 上的工作原理(how symlinks work on the Mac)。
10. 安排关机
如果要在经过特定时间后关闭 PC,请使用shutdown -f -t <time in seconds>命令。
在Mac上,请改用以下命令:
sudo shutdown -h +<time in minutes>
您始终可以使用sudo killall shutdown命令取消计划的关机。
11. 比较文件差异
在Windows上,您可以使用(Windows)fc命令 比较两个文件之间的差异。
Mac 的终端等效项是:
差异(diff)
diff命令带有多个选项。例如,您可以使用-i开关使其忽略文本文件中的大小写差异。运行man diff以查看完整的选项列表。
12. 查找 Wi-Fi 密码
每当您需要快速识别 Wi-Fi 连接的密码时(identify the password of a Wi-Fi connection),您可以在 PC 上使用netsh wlan show profile <SSID> key=clear。
在Mac上,您必须在(Mac)终端(Terminal)中运行以下命令:
security find-generic-password -ga “<SSID>” | grep “password:”
13.更新Mac
在Windows中,您可以通过(Windows)Windows PowerShell使用Get-WindowsUpdate和Install-WindowsUpdate命令安装操作系统更新。与使用GUI(GUI)相比,它更快、更慢。
更新 macOS的终端等效项是:(Terminal)
- softwareupdate -l扫描和查看挂起的更新和标识符。
- softwareupdate -i <identifier>安装更新。
14. 续签 IP 租约
释放和更新 IP(互联网协议)租约(renewing the IP (Internet Protocol) lease)可以解决您计算机上与连接相关的问题。这涉及通过Windows中的命令提示符运行(Command Prompt)ipconfig /release 和ipconfig /renew命令。
Mac 通过System Preferences(System Preferences) > Network > Wi-Fi / Ethernet > Advanced > DHCP > Renew DHCP提供 GUI 选项。但是,您也可以使用以下终端命令:
sudo ipconfig set <network interface> DHCP
如果您不知道网络接口名称,请使用ifconfig命令来识别它——例如en0。
15. 检查正常运行时间
您可以使用(get-date) – (gcim Win32_OperatingSystem).LastBootUpTime((get-date) – (gcim Win32_OperatingSystem).LastBootUpTime) Windows PowerShell 命令检查 PC 的正常运行时间。
在 macOS的终端(Terminal)上,改为运行以下命令:
正常运行时间(uptime)
uptime命令可帮助您确定是否该关闭或重新启动Mac。这通常有助于解决阻止 macOS 正常工作的随机技术故障。
切换到终端
Mac 的终端(Terminal)允许您在 PC 上使用命令提示符(Command Prompt)和Windows PowerShell执行您已经习惯的大多数任务。虽然上面的命令等价物并不详尽,但它们应该总是很方便。
15 Mac Terminal Equivalents to Windows Command Prompt and PowerShell Commands
In Windows, you can use the Command Prompt and Windows PowerShell consoles for greater control and faster management of the operating system. Both CLIs (command-line interpreters) also help you troubleshoot serious issues with your PC.
The same goes for the Mac’s Terminal, but its UNIX-based nature requires that you enter a different set of commands.
If you recently switched to using a Mac, you’ll learn the Terminal equivalents to 15 helpful Command Prompt and Windows PowerShell commands below.
1. View System Information
Suppose you want to identify the various hardware and software components (processor, RAM, operating system version, etc.) on your computer. In that case, you can view the information in Command Prompt or Windows PowerShell with the systeminfo command.
In Terminal, execute the following instead:
system_profiler
You can also prompt Terminal to filter the information by data type. For example, you can get an overview of Mac’s hardware only by appending SPHardwareDataType to the end of the command—e.g. system_profiler SPHardwareDataType.
For a list of data types, run the system_profiler -listDataTypes command.
To view the information via the GUI (graphical user interface) on your Mac, hold down the Option key and go to Apple menu > System Information.
2. Ping Devices and Networks
You can diagnose connectivity problems with websites and local devices by running the ping <host> command via Command Prompt or Windows PowerShell. That prompts your PC to transmit and receive data packets, and you get to spot irregularities in response times and packet loss.
The ping <host> command is universal to most CLIs, but Terminal does not set a ping count unless you execute it with the -c parameter as follows:
ping -c <count> <host>
3. Check Network Configurations
On the PC, running ipconfig via Command Prompt loads the Internet Protocol Configuration utility. It allows you to identify TCP/IP network configurations along with information about IP addresses, subnet masks, default gateways, and so on.
The Terminal equivalent opens Interface Configuration and uses the following command:
ifconfig
By default, ifconfig displays active networks only. To make it show all interfaces, run ifconfig -a instead.
4. Flush DNS Cache
An outdated Domain Name System (DNS) cache on your computer causes connectivity issues with websites. In Windows, running the ipconfig /flushdns command via an elevated Command Prompt console helps you clear your computer’s local DNS cache.
The Terminal equivalent to clearing the DNS cache on Mac is as follows:
sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder
You must enter an administrator password to authorize the command.
5. View All Running Processes
Compared to the Windows Task Manager, typing tasklist into Command Prompt or Windows PowerShell allows for a clearer view of your PC’s background processes. It also contains information such as process IDs (PIDs) and memory usage stats for each task.
On the Mac, you can run one of the two commands below:
The top command displays a list of the most resource-intensive processes in real-time, while ps -ax shows you the complete task list on your Mac.
6. End Process
You can also use Command Prompt and Windows PowerShell to end running processes with the taskkill <PID> command.
The Mac’s Terminal equivalent is:
kill <PID>
Additionally, you can use the killall <process name> command to end all Mac processes containing a particular name—e.g. Garageband. Here’s the complete guide to shutting down Mac processes using Terminal.
7. Check Network Statistics
The netstat command in Windows lets you view a list of all active TCP connections and helps identify network-related problems.
On the Mac, running the same command yields similar results:
netstat
To view a list of flags and options specific to Terminal, type man netstat.
8. Repair Disk Errors
The Check Disk command-line utility on Windows, which you can invoke by running chkdsk in Command Prompt or Windows PowerShell, allows you to check for and repair disk-related errors.
The Terminal equivalent in macOS is the fsck (file system consistency check) command. Start by booting up your Mac in single-user mode—press Command + S at startup. Then, run the following:
/sbin/fsck -fy
9. Create Symbolic Link
Symbolic links (symlinks) are crucial if you find it impossible to change locations that apps and programs use to store files.
For example, you can use a symlink to sync any folder to a cloud storage service by making it appear as if it’s inside the default sync directory. On Windows, you use the mklink /J command.
On macOS, the Terminal equivalent is:
In -s <original folder path> <target folder path>
To learn more, check out how symlinks work on the Mac.
10. Schedule Shut Down
If you want to shut down your PC after a specific amount of time has elapsed, you use the shutdown -f -t <time in seconds> command.
On the Mac, use the following command instead:
sudo shutdown -h +<time in minutes>
You can always use the sudo killall shutdown command to cancel a scheduled shutdown.
11. Compare File Differences
On Windows, you can compare the difference between two files using the fc command.
The Mac’s Terminal equivalent is:
diff
The diff command comes with multiple options. For example, you can use the -i switch to make it ignore case differences in text files. Run man diff to view a complete list of options.
12. Find Wi-Fi Password
Whenever you need to identify the password of a Wi-Fi connection quickly, you can use the netsh wlan show profile <SSID> key=clear on your PC.
On the Mac, you must run the following command in Terminal:
security find-generic-password -ga “<SSID>” | grep “password:”
13. Update Mac
In Windows, you can install operating system updates via Windows PowerShell with the Get-WindowsUpdate and Install-WindowsUpdate commands. It’s faster and less sluggish compared to using the GUI.
The Terminal equivalents to update macOS are:
- softwareupdate -l to scan for and view pending updates and identifiers.
- softwareupdate -i <identifier> to install an update.
14. Renew IP Lease
Releasing and renewing the IP (Internet Protocol) lease can fix connectivity-related issues on your computer. That involves running the ipconfig /release and ipconfig /renew commands via Command Prompt in Windows.
The Mac provides a GUI option via System Preferences > Network > Wi-Fi/Ethernet > Advanced > DHCP > Renew DHCP. However, you can also use the following Terminal command:
sudo ipconfig set <network interface> DHCP
If you don’t know the network interface name, use the ifconfig command to identify it—e.g. en0.
15. Check Uptime
You can check your PC’s uptime with the (get-date) – (gcim Win32_OperatingSystem).LastBootUpTime Windows PowerShell command.
On the Terminal in macOS, run the following command instead:
uptime
The uptime command helps you determine if it’s time to shut down or restart your Mac. That often helps resolve random technical glitches preventing macOS from working correctly.
Switching to Terminal
The Mac’s Terminal allows you to perform most tasks that you’ve gotten accustomed to with Command Prompt and Windows PowerShell on the PC. While the command equivalents above aren’t exhaustive, they should be handy always.