Making the Facebook Papers Public
Subtitles
  • Off
  • English

20 Cool Command Line Tricks for Windows and macOS

20 Cool Command Line Tricks for Windows and macOS

These classic computing interfaces can help you get more done on your devices.

We may earn a commission from links on this page.
Start Slideshow
Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

The command line interface is a throwback to a more basic age of computing. Before mouse pointers and application windows and desktop wallpaper, you would interact with your computer through simple text commands typed into the command line. It was more rudimentary, but it had an appealing simplicity to it.

Advertisement

Nowadays we launch programs with a double-click of an icon rather than a string of text, but the command line lives on. It’s called Command Prompt (or the Windows Command Processor) in Windows, and takes the form of Terminal in macOS. Windows also has a slightly more powerful version of Command Prompt called PowerShell.

How to Pull Up the Command Line

In Windows, just typing “cmd” into the taskbar search box and hitting Enter launches Command Prompt, but for some of these commands you need administrator privileges. To get them, launch Task Manager with Ctrl+Shift+Esc, then choose File and Run new task. Enter “cmd” in the box, make sure admin privileges are ticked, and click OK. Use the “| more” flag after any command to see the results a page at a time (that’s the pipe character at the start, or append “c:\export.txt” to send the output to a text file, then change its name and location as you like.

To launch the Terminal in macOS, open up Spotlight with Cmd+Space and then type “Terminal” until it appears on screen—select it, hit Enter, and you’re in. As with Windows, use “| more” at the end of your commands to go a page at a time through the results or responses, or “> export.txt” to save the results in a text file in the current directory (it defaults to the current user’s directory).

Let’s get started.

Advertisement
Previous Slide
Next Slide

2 / 22

1. View Installed Drivers (Windows)

1. View Installed Drivers (Windows)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

If you’re troubleshooting hardware problems or just want to know if something’s installed successfully, seeing a list of installed drivers can help. Type “driverquery” then Enter, and you get a list of all the current Windows drivers, alongside install dates and display names.

Advertisement
Previous Slide
Next Slide

3 / 22

2. Watch Star Wars in ASCII (Windows, macOS)

2. Watch Star Wars in ASCII (Windows, macOS)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

No, really. Type “telnet towel.blinkenlights.nl” then Enter to watch the entirety of Episode IV in ASCII. The same trick works on macOS, too. You do need to make sure Telnet is installed on Windows though: Search “turn Windows features on or off” from the taskbar.

Advertisement
Previous Slide
Next Slide

4 / 22

3. Save Folder Trees to Disk (Windows)

3. Save Folder Trees to Disk (Windows)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

Struggling to get an overview of all the nested folders on a drive? The command line can help. Type “tree” and hit Enter to see the current folder and its subfolders neatly laid out. Add “> c:\export.txt” to save the results in a text file that you can browse at your leisure.

Advertisement
Previous Slide
Next Slide

5 / 22

4. Scan for System Problems (Windows)

4. Scan for System Problems (Windows)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

Nobody wants their Windows system crashing and shutting down on a regular basis. If you’re having problems, then the “sfc /scannow” command, which launches the System File Checker tool, checks the most important OS files and fixes them, if possible.

Advertisement
Previous Slide
Next Slide

6 / 22

5. Show Your Wifi Password (Windows)

5. Show Your Wifi Password (Windows)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

Forgot your wifi password? Use the command “netsh wlan show profile SSID key=clear” and just replace “SSID” with the name of the wifi network. If you’re not sure about the networks you’re connected to, use the “netsh wlan show profile” command.

Advertisement
Previous Slide
Next Slide

7 / 22

6. Shut Your Computer Down Later (Windows)

6. Shut Your Computer Down Later (Windows)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

Shut down your computer in the future with “shutdown”—add “-t xxx” to delay it by xxx number of seconds (from 0 to 315,360,000, which is 10 years) and “-f” to force close any dialogs. As an example, to shut your computer down in 636 seconds, you type “shutdown -f -t 636".

Advertisement
Previous Slide
Next Slide

8 / 22

7. Check Your Laptop’s Battery Health (Windows)

7. Check Your Laptop’s Battery Health (Windows)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

The command prompt can give you a pretty detailed and technical readout of the battery health of your laptop (or tablet). Type “powercfg /batteryreport” and hit Enter to generate the report, then open C:\WINDOWS\system32\battery-report.html to view the findings.

Advertisement
Previous Slide
Next Slide

9 / 22

8. View Your License Key (Windows)

8. View Your License Key (Windows)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

Lost your Windows license key again? If it’s not printed on your computer case or on any documentation, then you can find it by typing “wmic path softwarelicensingservice get OA3xOriginalProductKey” into the command prompt window, then hitting Enter.

Advertisement
Previous Slide
Next Slide

10 / 22

9. Fix Internet Problems (Windows)

9. Fix Internet Problems (Windows)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

The command “ipconfig” shows your network connection status (the gateway is your router, if you need to know its IP), but you can also use “ipconfig /release” and then “ipconfig /renew” to reset your internet connection, which can solve multiple issues.

Advertisement
Previous Slide
Next Slide

11 / 22

10. Get Information About Your PC (Windows)

10. Get Information About Your PC (Windows)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

It’s not always easy to figure out where to find your computer’s specs—that is, it’s not easy unless you use the command line. Type “systeminfo” and press Enter to get a detailed readout of everything from the amount of RAM installed to when the last reboot was.

Advertisement
Previous Slide
Next Slide

12 / 22

11. Change the Default Screenshot Type (macOS)

11. Change the Default Screenshot Type (macOS)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

Screenshots you take on macOS are saved as PNG files by default, but you don’t have to settle for this. Type “defaults write com.apple.screencapture type JPG” and hit Enter to change the format to JPEG, for example. Other file formats you can use are PDF and TIFF.

Advertisement
Previous Slide
Next Slide

13 / 22

12. Get Your Mac to Speak to You (macOS)

12. Get Your Mac to Speak to You (macOS)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

macOS comes with a text-to-speech engine, and getting it running in Terminal is as simple as typing “say” followed by any text in quotation marks, then Enter. Admittedly this isn’t all that useful, but it’s still fun to play with... maybe for breaking the silences at work?

Advertisement
Previous Slide
Next Slide

14 / 22

13. Add a Message to the Login Screen (macOS)

13. Add a Message to the Login Screen (macOS)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

You can add a login screen message through Terminal, maybe with contact details in case your Mac gets lost. Use “sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText” and then a space, then your message in quotation marks. Hit Enter.

Advertisement
Previous Slide
Next Slide

15 / 22

14. Rebuild Spotlight (macOS)

14. Rebuild Spotlight (macOS)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

Over time, the Spotlight search function can become sluggish and a little bloated, but you can use Terminal to rebuild its index. Type “sudo mdutil -E /Volumes/DriveName” and replace DriveName with your actual drive name (which will usually be “Macintosh HD”).

Advertisement
Previous Slide
Next Slide

16 / 22

15. Get a Dictionary Definition (macOS)

15. Get a Dictionary Definition (macOS)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

If you don’t happen to have a proper paper dictionary or a search engine on hand then Terminal can look up words for you as well. All you need to do is type “curl dict://dict.org/d:word” and replace that final “word” with the one you want defined.

Advertisement
Previous Slide
Next Slide

17 / 22

16. Keep Your Computer Awake (macOS)

16. Keep Your Computer Awake (macOS)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

To prevent your Mac’s screen from dimming or initiating the screensaver, you can simply type “caffeinate” into a Terminal window and press Enter (use Ctrl+C to return to normal). Add “-t xx” to specify a duration for the wakefulness, with “xx” the number of seconds. So if you wanted an hour of wakefulness for example, you’d type “caffeinate -t 3600".

Advertisement
Previous Slide
Next Slide

18 / 22

17. Show Hidden Files (macOS)

17. Show Hidden Files (macOS)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

You can reveal the files macOS is hiding from you with the “defaults write com.apple.finder AppleShowAllFiles -bool TRUE; killall Finder” command. If you need to hide them again, use the “defaults write com.apple.finder AppleShowAllFiles -bool FALSE; killall Finder” command.

Advertisement
Previous Slide
Next Slide

19 / 22

18. See When You Last Shut Down Your Computer (macOS)

18. See When You Last Shut Down Your Computer (macOS)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

This simple command can come in handy: Just type in “uptime” in the Terminal window to see how long it’s been since you last shut down your Mac. If you can’t remember when the OS was last updated or need to troubleshoot your machine, it can be quite useful.

Advertisement
Previous Slide
Next Slide

20 / 22

19. Shut Down Your Mac, With a Delay (macOS)

19. Shut Down Your Mac, With a Delay (macOS)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

As with Windows, you can shut down your macOS machine from Terminal, and add a delay if necessary (if something needs to finish first, for instance). The command “sudo shutdown -h now” does a full shutdown, whereas “sudo shutdown -h +5" delays it for five minutes.

Advertisement
Previous Slide
Next Slide

21 / 22

20. Add Spaces to the Dock (macOS)

20. Add Spaces to the Dock (macOS)

Image for article titled 20 Cool Command Line Tricks for Windows and macOS
Screenshot: Gizmodo

Add spaces to the Dock with the “defaults write com.apple.dock persistent-apps -array-add ‘{”tile-type”=”spacer-tile”;}’; killall Dock” command—run it as many times as you want spaces. To get rid of a space you’ve added, just drag it to the Trash.

Advertisement