30 Terminal tips, tricks and projects for Mac

At startup, Terminal presents a line interface you could use to management components of the macOS interface – primarily, it offers you entry to the UNIX options which are exterior the macOS pores and skin. Here we’ll check out some projects you possibly can strive out in Terminal, utilizing your newly discovered expertise.

If you are new to Terminal, or when you want to brush up in your instructions, it is best to begin with our introductory function you could read right here: Using Terminal on a Mac.

Note that the place you see sq. brackets, you want to add your individual enter, often a file path or URL, without the sq. brackets.

1. Show hidden data and folders

macOs creates hidden data and folders for a number of causes. Usually there is no such thing as a cause for us to know them and even know they exist, however, when you want to observe 1 down you are able to do that with Terminal. Type:

defaults write com.apple.finder AppleShowAllFiles bool TRUE

killall Finder

Change TRUE to FALSE if you need to conceal the data once more.

2. Copy data from 1 folder to 1 other

Option to drag and drop data to copy them from 1 place to 1 other is really easy. Instead, strive Terminal’s Ditto command.

Type: similar

Where ‘unique folder’ and ‘new folder’ are the file paths of the supply and vacation spot of the data. Type ‘-v’ after Ditto to see the identify of every file within the Terminal window as it’s being copied. This is the command for prolonged mode.

3. Download data without your browser

If you will have the URL of a file that you simply want to download however, don’t desire to download it in Safari, Chrome or Firefox, Terminal will help. It solely wants 2 instructions: 1 to set Terminal’s location in your Downloads folder (or wherever else you need to put the downloaded file) and 1 to download the file. Use the command under to set the situation. Change ‘Downloads’ to a unique folder if you need, do not forget that if it is not within the first stage of your person listing, you will have to kind the complete path – or drag the folder to the Terminal window.

cd ~ / Downloads /

To download the file:

curl -O

4. Disable drop shadows on a screenshot

When you use Command-Shift-4 the area bar to make a display screen seize of a window in your Mac, a drop shadow is added to the window. If you’d somewhat not have it, use this command to take a screenshot without drop shadow.

$ default write com.apple.screencapture disable-shadow -bool TRUE

killall SystemUIServer

5. Keep your Mac awake

Overriding the sleep settings in Power Preferences requires just 1 command.

caffeine

Type Ctrl-C to finish the command or time restrict as follows

caffeine -u -t

6. Automatically restart your Mac after a crash

When your Mac freezes or crashes, typically the 1 answer is to maintain down the facility button and wait for it to restart. Use this command to routinely restart when it detects a crash.

sudo systemsetup -setrestartfreeze

7. Hide inactive apps in your Dock

Dock too busy, use this to present solely working apps.

defaults write com.apple.dock static solely bool TRUE

killall Dock

8. Boring hidden apps within the Dock

You can go even additional and create the Dock dim apps that aren’t seen on the display screen.

defaults write com.apple.Dock showhidden -bool TRUE

killall Dock

9. Make holding down a key repeat characters

Here’s 1 we actually like. When you maintain down a key in your Mac’s keyboard, a pop-up with extra characters seems or nothing is completed. Here’s how to get it to repeat the character you typed, identical to it used to.

default write -g ApplePressAndMaintainEnabled -bool FALSE

Use the identical command to undo the command, however, exchange ‘FALSE’ with ‘TRUE’

10. Hide data and folders within the Finder

chflags hidden

11. Play Tetris, Pong, Snake and different games

Emacs, the textual content editor pre-installed with macOS and working from the terminal, has quite a few Easter eggs within the type of games.

Type to show them Emacs then press enter, then Fn and F10 the reafter t the reafter g

You will see the out there games within the record and can now use the cursor keys to choose them.

12. Write ASCII artwork banners

Type: banner -w


13. Enable an iOS-like energy bubble when related to the facility provide

Use this to make your Mac sound like an iPhone whenever you plug within the charger.

defaults write com.apple.PowerChime ChimeOnAllHardware -bool true; open /System/Library/CoreServices/PowerChime.app

14. Check for macOS updates more typically

To change the frequency with which your Mac checks for macOS updates from weekly to each day, kind:

defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1

15. Download data without your browser

If you will have the URL of a file that you simply want to download however, don’t desire to download it in Safari, Chrome or Firefox, Terminal will help. It solely wants 2 instructions: 1 to set Terminal’s location in your Downloads folder (or wherever else you need to put the downloaded file) and 1 to download the file. Use the command under to set the situation. Change ‘Downloads’ to a unique folder if you need, do not forget that if it is not within the first stage of your person listing, you will have to kind the complete path – or drag the folder to the Terminal window.

cd ~ / Downloads /

To download the file:

curl -O

16. View the contents of a folder

The “ls” command shows the contents of a folder. Adding ‘-R’ enlarges subfolders. So to see all of the contents of a folder, kind:

ls -R


17. Recover a disk picture to a quantity related to your Mac

Use this command when you’ve got a disk picture that you really want to make an actual quantity:

$ sudo asr -restore -noverify -source / goal /

18. View the contents of every file

If you’ve got ever despatched a file that may’t be opened in your Mac, for instance as a result of you do not have an app that may open it or as a result of it is corrupt, you possibly can view its contents in Terminal. For many data, reminiscent of audio and video, the textual content you see doesn’t suggest a lot. For others, there could also be simply sufficient to dissect what you want.

Type: cat

Tip: Instead of manually typing the trail to the file, you possibly can drag it to the Terminal window and drop it after the command.

19. Change the default screenshot location

You can change the place screengrabs are saved by typing:

defaults write com.apple.screencapture location

Then press Enter and then:

killall SystemUIServer

And press Enter once more.

20. Prevent apps from being saved to iCloud by default

Some macOS apps like TextEdit and iWork apps save to iCloud by default. You can change that by:

defaults write NSGlobalDofundamental NSDocumentSaveNewDocumentsToCloud -bool false

To return to iCloud, use the identical command with the flag set to ‘true’

21. How to change file permissions with Terminal

File permissions management which customers can entry and change data and folders in your Mac. Usually they work very effectively, however, often issues go unsuitable, like whenever you copy a file from 1 person account to 1 other and find you could’t open it in your account.

There are 2 instructions we will use to change permissions; chmod, which modifications permissions for all customers besides the file proprietor, and chown, which assigns possession to a particular person.

So to change the permissions for a file so that everybody can open, read and modify the file, we use:

sudo chmod 777 path-to-file

Where path-to-file is the trail of the file whose rights you need to change. Remember, as a substitute of typing the file path, you possibly can drag the file into the Terminal window. If you need to change the permissions to permit entry and read, however, don’t desire to permit the file to be modified, exchange 777 with 644.

To change the permissions on all data in a folder, drag the folder to the Terminal window as a substitute of a file and kind -R after the command identify.

Use the next to change possession of a file in your account:

sudo chown your-short-username path-to-file

22. Change the default for screenshots on Mac

OS X screenshots are saved as .png data by default. That’s often tremendous, however, you possibly can change it if essential. For instance, to change the default to jpeg, kind:

defaults write com.apple.screencapture kind JPG

You may swap to PDF or TIFF with the identical command and swap your chosen format to JPG.

Use the next to change the default identify for screenshots:

default write com.apple.screencapture identify “the-name-you-chose”; killall SystemUIServer

Replace the identify you selected with no matter you need and screenshots will now be on condition that identify, adopted by the date and time.

23. View an ASCII model of Star Wars

This 1 is simply for enjoyable, however, how enjoyable! There is an ASCII model of Star Wars on a Telnet server within the Netherlands. To view it use:

telnet towel.blinkenlights.nl

Type Ctrl-]to cease it

and then ‘cease’

24. Enable textual content choice in Quick view

Quick Look is an extremely great tool for shortly viewing the contents of a file. And whereas it’s primarily for photos, it can be used to read textual content paperwork. Unfortunately, studying is so far as it goes. For instance, you can not choose textual content to copy it. At least not without the assistance of a Terminal command. Type this to choose the textual content in Quick Look:

defaults write com.apple.finder QLEnableTextSelection bool TRUE; killall Finder

We have an entire tutorial for choosing and copying textual content from Quick Look samples in OS X right here.

25. Disable Auto-recovery in Preview with Terminal on Mac

Do you ever open Preview and find it spits open doc home windows throughout your display screen? That’s the flaw of Auto-restore, a function in OS X since Lion, that saves the state Preview is in whenever you exit it and returns it to that state whenever you open it once more. So until you shut all open paperwork earlier than closing, they may open once more the following time you begin Preview.

To keep away from this and begin Preview without paperwork, use this Terminal command:

defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool FALSE

To revert to the default, retype the command and exchange FALSE with TRUE. Replace com.apple.Preview with com.apple.QuickTimePlayerX to do the identical in QuickTime X

26. Make the Dock slide quicker with Terminal on the Mac

If you use Show and Hide Dock, you’ll find that whenever you drag the mouse pointer to the underside of the display screen, or whichever approach you save the Dock, the re’s a delay earlier than the Dock comes into view. You can remove that delay with these instructions:

default values ​​write com.apple.dock autohide-delay-float 0

killall Dock

The ‘0’ represents the delay earlier than the Dock comes into view, so if you need to scale back it however, not utterly remove it, exchange the ‘0’ with a unique worth, measured in seconds.

To revert to the default, kind:

default settings take away com.apple.dock autohide-delay

killall Dock

You may change the velocity at which the Dock slides. Again, it’s accomplished by adjusting a delay. So, to make it direct, kind:

defaults write com.apple.dock autohide-time-modifier-float 0

killall Dock

To double the velocity, exchange the ‘0’ with ‘0.5’ and use ‘1’ to hold it because it was.

27. Add a message to the login window

Whether it is fooling different customers, giving each day affirmations or inspiration to your self, or for another cause, you might have considered trying to publish within the login window in OS X. Using Terminal it is rather easy. Type:

$ sudo by default writes /Library/Preferences/com.apple.loginwindow LoginwindowText “Your message here”

The subsequent time you log out or restart, the message will seem within the login window. To take away it, use:

By default, $ sudo is delete /Library/Preferences/com.apple.loginwindow

28. Let your Mac converse

You can have your Mac say something you need with the presently chosen voice. To do that, use the ‘Say’ command, like this:

Say “whatever you want your Mac to say”

As quickly as you press Return, your Mac will say the phrases you typed.

29. Remove Dashboard

Let’s face it, who not makes use of Dashboard? For most of us, the 1 indication of survival is exhibiting up in Mission Control. If you need it to be utterly gone, use this command:

defaults write com.apple.dashboard mcx-disabled -boolean TRUE

killall Dock

Use the identical command to carry it again, however, exchange TRUE with FALSE.

30. Rebuild Spotlight

Spotlight is OS X’s search device and 1 that’s extremely helpful. Occasionally, nevertheless, it could get broken or cease working correctly. The answer is to rebuild it. Guess? Yes, the re’s additionally a Terminal command for that. Use:

sudo mdutil -E / Volumes / DriveName

Where ‘DriveName’ is the identify of the quantity whose index you need to rebuild. In most circumstances that is your boot quantity and until you will have modified it it’s known as ‘Macintosh HD’. Alternatively, when you’ve got mounted volumes in your Mac’s desktop, you possibly can drag the 1 you need to the Terminal window and ignore ‘/ Volumes / DriveName’.

Read the next:

What Automator can do for you

Excellent Automator workflows

How to repair WiFi issues

How to view your Mac or PC display screen on an iPad

Compsmag
Logo
Shopping cart