只要终端(Terminal)窗口保持打开状态,您的Mac就不会进入睡眠状态。(Mac)您还可以通过添加-t <time in seconds>参数来防止 Mac 在(prevent the Mac from falling asleep)特定时间内进入睡眠状态,例如caffeinate -t 3600。
Τhe Mac’s Terminal is incredibly powerful. Not only does it let things get done faster without the GUI (graрhical user interface) slowing you down, it also allows you to perform tasks that you cаn’t complete any other way. Howeνer, you don’t have to be а Termіnal expert—or even like using commаnd-line interpreters—to take advantage оf it.
Whether you’re totally new to the Terminal or just warming up to it, the list of 10 Mac Terminal commands below should help you improve the experience with your Mac. You can execute them in a matter of seconds.
Even if you know your way around the Terminal, you may still run into the odd command that fell under your radar all along. So do keep reading.
1. Keep Your Mac Awake
Remember the last time your Mac went to sleep and ended up pausing or canceling that download—or whatever else—it was performing? If you hate modifying the sleep settings each time you want to stop that, simply fire up Terminal and run the Mac Terminal command below:
caffeinate
Your Mac won’t go to sleep as long as the Terminal window remains open. You can also prevent the Mac from falling asleep for a specific amount of time only by adding the -t <time in seconds> argument—e.g., caffeinate -t 3600.
2. Change Screenshot Format
By default, your Mac saves your screenshots in the PNG format. But you can change that to the much more lightweight JPG format with the command below:
defaults write com.apple.screencapture type JPG
Additionally, you can use the same command to switch to alternative formats such as TIFF, BMP, and PSD. Just replace JPG (toward the end) with the image extension you want.
3. Ping Websites and Devices
If you have issues connecting to a website, you can try pinging it. Simply type the following command but replace <host> with the web address or IP (Internal Protocol) address. The command also applies to devices within the local network, including the router itself.
ping <host>
Your Mac should send packets of data repeatedly and display the response times in milliseconds. Press Control+C to stop the command.
To run the command with a set number of data packets, use the -c <number of packets> argument—e.g., ping -c 4 google.com.
4. Flush DNS Cache
Your Mac’s DNS (Domain Name System) cache consists of “resolved” domain names in IP address form. If the DNS cache gets outdated or corrupt, you may run into issues accessing or loading websites.
Did you know that you could download files directly via the Terminal itself? If you have trouble performing a download with your web browser, type the command below into Terminal, replacing <url> with the download URL.
curl -O <url>
The file should begin downloading right away, along with information such as download speed and data received.
By default, the command downloads files to the root of your Mac user account. You can change that beforehand (to the Mac’s Downloads directory, for example) with the Change Directory—cd—command
Start by changing the Terminal directory to the folder that contains the folder you want to compress. For example, if it’s located on the desktop, type the following:
cd ~/Desktop/
Then, follow up with the command below:
zip -er <output folder name.zip> <source folder name>
Replace <output folder name.zip> and <source folder name> with the names of the output folder and the source folder, respectively.
For example, if you want to compress a folder labeled PDFs and label the resulting ZIP file with the same name, type zip -er PDFs.zip PDFs. Then, enter and verify the password you want to add to the ZIP file.
8. Create Symbolic Links
Symbolic links are folder shortcuts that point to different locations on the Mac. They are convenient and allow you to do all sorts of things. For example, you can change the default backup destination for iPhone backups or sync folders to iCloud without shifting things around. The Mac Terminal command to create a symlink is as follows:
ln -s </path/to/original> </path/to/link>
Replace </path/to/original> with the target directory, and </path/to/link> with the location that should contain the symlink.
The screenshot below displays a command instructing Terminal to create a symlink in iCloud Drive pointing to a folder labeled PDFs within the Mac’s Documents folder.
You can schedule your Mac to shut down after a specified amount of time. Type the following command, replacing <time> with the time duration in minutes:
$ sudo shutdown -h <time>
Alternatively, you can prompt your Mac to restart by replacing -h with the -r argument—e.g., $ sudo shutdown -r 60.
10. Talking Mac
This is a fun command:
say <words>
Replace <words> with whatever you want, and your Mac should start speaking as soon as you press Enter!
You can also make the Mac speak in different voices. A couple of examples include:
say -v fred <words>
say -v samantha <words>
Tip: Type say -v ? and press Enter to reveal additional voices.
15 Additional Terminal Commands for Mac
Can’t get enough of the Terminal? Here are 15 additional commands that you should know.
Action
Command
View Running Processes
top
Check Mac’s Uptime
uptime
Reveal IP Address
curl ipecho.net/plain; echo
Display Wireless Access Point
netstat -nr | grep default
View Hidden Files in Finder
defaults write com.apple.Finder AppleShowAllFiles true;killall Finder
Change Default Screenshot Name
defaults write com.apple.screencapture name “New Name”;killall SystemUIServer
The Mac Terminal commands above aren’t exhaustive by any means, but they should provide lots of use cases as you keep using your Mac. If you have any favorites that didn’t make the list, feel free to share them in the comments below.