Mac

30 Terminal Tips and Tricks for MacOS

In this article, we will fully describe some of the best uses for MacOS command line. Including: How to watch an ASCII version of Star Wars on a Mac using the terminal.

When running the Terminal, a command line interface is provided that you can use to control parts of the Mac interface. It basically lets you access the UNIX features that go beyond the Mac shell. Here we will focus on projects that you can use to gain new skills.

If you are new to the terminal, or need to know more about entering the command line, the best place to start is our terminal introduction article, which you can read here: How to use the terminal on a macOS.

Note that where you see square brackets, you must add your input, usually a file path or URL, without the square bracket.

1. Show hidden files and folders

Mac creates hidden files and folders for a variety of reasons. Most of the time, there is no reason for us to be aware of their existence or even to know that they exist. But if you need to track one of them, you can do it with the terminal. just type the follwing command:

defaults write com.apple.finder AppleShowAllFiles -bool TRUE

killall Finder

Change TRUE to FALSE when you want to hide the files again.

Copy files from one folder to another

The option to drag and drop files to copy them from one place to another is very fast. Instead, try the terminal Ditto command.

Ditto [original folder] [new folder]

On the command line are the [original folder] and [new folder] options, the source and destination paths of the files. To view the name of each file in the terminal window as copied, type -v after Ditto. This command is long.

Copy file from one folder to another

3. Download files without using a browser

If you have the URL of the file you want to download, but do not want to download it in Chrome, Safari or Firefox, the terminal can help you. This requires only two commands: one to locate the terminal in your Downloads folder (or wherever you want to place the downloaded file) and one to download the file. Use the following command to set the download location. If you wish, you can switch the Downloads to another folder, noting that if this is not in the first level of your user directory, you must type the full path – or drag the folder to the terminal window.

cd ~/Downloads/

curl -O [the URL of the file]

4. Disable bounce shadows in a screenshot

When you use the shortcut keys Command + Shift + 4 + Spacebar to take a screenshot of a window on your Mac, a raised shadow is added to the window. If you prefer not to have this shadow in your screenshots, use this command to take a screenshot without a raised shadow.

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

killall SystemUIServer

5. Keep your Mac awake

Setting sleep settings in Energy preferences requires only one command.

caffeinate

Type Ctrl-C to end the command or time limit like this.

caffeinate -u -t [seconds]

6. Restart the Mac automatically after a crash

When your Mac freezes or crashes, usually all you can do is hold down the power button and wait for it to restart. This command automatically restarts when the Mac senses a crash.

sudo systemsetup -setrestartfreeze on

7. Hide inactive programs in the Dock

If the Dock is too busy, use this command to show only active applications in the Dock.

defaults write com.apple.dock static-only -bool TRUE

killall Dock

8. Disable hidden programs in the Dock

You can go a step further and put hidden apps in the Dock that are not visible on the screen.

defaults write com.apple.Dock showhidden -bool TRUE

killall Dock

9. Create by holding down a key to repeat letters


This is something we really like. When you hold down a key on your Mac keyboard, it either displays a pop-up dial or does nothing. Here’s how to put one on top of the other, just like you used to.

defaults write -g ApplePressAndHoldEnabled -bool FALSE

10. Hide files and folders from view in Finder

Use the following command for this purpose:

chflags hidden [Path of the file]

Perform Tetris, Pong, Snake and other games

Emacs, a text editor pre-installed on the Mac and running from the terminal, comes with a number of games.

To display them, type Emacs and press Enter, then Fn and F10 then t and then g.

You will see the available games listed, and now you can use the cursor keys to select them.

12. Write ASCII art banners

Type the following command:

banner -w [width in pixel] [text]

13. Activate a power sound like IP. She. When connecting to electricity

Use this option to make your Mac look like it does when you plug in an iPhone to charge.

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

14. Check back more for Mac updates

Type the following command to change the frequency of checking your Mac for weekly updates:

defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1

15. Download files without using a browser

If you have the URL of the file you want to download, but do not want to download it in Chrome, Safari or Firefox, the terminal can help. This requires only two commands: one to locate the terminal in your Downloads folder (or wherever you want to place the downloaded file) and one to download the file. Use the following command to set the download location. If you wish, you can switch the Downloads to another folder, noting that if this is not in the first level of your user directory, you must type the full path – or drag the folder to the terminal window.

cd ~/Downloads/

To download the file:

curl -O [the URL of the file]

16. List the contents of a folder

The ls command displays the contents of a directory that expands by adding -R to subfolders.

ls -R [Path]

17. Restore an image disk to a volume associated with a Mac

If you have an image disk that you need to create a volume from, use this command:

$ sudo asr -restore -noverify -source /[path to diskimage] -target /[Volume you want to restore to]

18. View the contents of each file

If you have a file sent to you that does not open on your Mac, you may be able to view its contents in the terminal, perhaps because you do not have an application that can open that file, or because the file is corrupted. For many files, such as audio and video files, the text you see will not make much sense. For other files, this may not be enough to get what you need. To do this, type the following command:

cat [path]

Note: Instead of typing the file manually, you can drag it to the terminal window and release it after the command.

19. Change the default location for storing screenshots

You can change the location of the screenshots. To do this, type the following command:

defaults write com.apple.screencapture location [The address where you want the screenshots to be stored]

Then press Enter and then enter the following command:

killall SystemUIServer

And press Enter again.

20. Prevent the default saving of applications in iCloud

Some Mac apps. She. Sites like TextEdit and iWork save their files in iCloud by default. You can change it using the following command line:

defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false

To return to the default iCloud storage, use the same command and use only true instead of false.

21. How to change file permissions using the terminal

Controls file permissions that users can access and modify files and folders on your Mac. They work great, but sometimes things go wrong, like when you copy a file from one account to another and find that you can’t open it in your account.

There are two commands we can use to change permissions; chmod, which changes permissions for all users except the file owner, and chown, which assigns ownership to a specific user.

Therefore, to change the permissions on a file, to access, read, and modify the file to anyone, we use this command:

sudo chmod 777 path-to-file

Here is the path-to-file path of the file whose permissions you want to change. Keep in mind that instead of typing the file path, you can drag the file to the terminal window. Replace 777 with 644 to change permissions to allow access and read without permissions on the file.

If you want to change the permissions for all files in a folder, drag the folder to the terminal window instead of a file, then type the -R command after the name.

To change the ownership of a file to your account, use the following command:

sudo chown your-short-user-name path-to-file

22. Change the default screenshots format on Mac

Screenshots in OS X are formatted by default. png are saved. This is usually a good format, but you can change the format if you wish. For example, to change the default format to jpeg, type the following command:

defaults write com.apple.screencapture type JPG

You can also use the same command to convert to PDF or TIFF format and replace the selected format with JPG.

Use the following command to rename the default screenshots:

defaults write com.apple.screencapture name “the-name-you’ve-chosen”; killall SystemUIServer

Replace the-name-you’ve-chosen with whatever you like so that screenshots with that name and date will be saved later.

23. Watch an ASCII version of Star Wars

This is just for fun, but very interesting! There is an ASCII version of Star Wars on a Telnet server in the Netherlands. To watch it, use the following command:

telnet towel.blinkenlights.nl

24. Enable text selection in Quick Look

Quick Look is an extremely useful tool for quickly reviewing the contents of a file. And although it is primarily intended for images, it can also be used to read text documents. Unfortunately, you can only read them. For example, you can not select text to copy. At the very least, it is not possible without the help of a terminal command. Type the following command to allow you to select text in Quick Look:

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

25. Disable auto-retrieval in Preview using the terminal on the Mac

Ever open Preview and see a series of pop-up windows pop up all over your screen? This is the fault of Auto-restore, a feature in OS X since Lion, which saves the status when you leave the Preview and when you reopen it, it opens the same way before leaving. Unless you close all open documents before exiting Preview so that they do not reopen the next time you run Preview.

To prevent this and run the Preview without opening any documents, use this terminal command:

defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool FALSE

To return to the default mode, type the command again and replace TRUE with FALSE. To do the same command in QuickTime X, com. apple. Preview the command with com. apple. Replace QuickTimePlayerX.

26. Show Dock faster using terminal on Mac

If you are using Hidden Dock mode, you will notice that there is a delay before the Dock is displayed when you move the mouse pointer down the screen or hold any of the edges of the Dock. You can use this command to eliminate that delay:

defaults write com.apple.dock autohide-delay -float 0

killall Dock

A value of zero indicates the delay before showing the Dock. So if you want to reduce the time but do not eliminate it, replace zero with another value. You must enter this value in seconds.

To return to the default mode, type the following command:

defaults delete com.apple.dock autohide-delay

killall Dock

You can also change the speed of the slide time. Because sliding is also delayed. Therefore, to eliminate this delay, use the following command:

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

killall Dock

To double the speed, replace zero with 0.5, and use 1 to maintain the same position as before.

27. Add a message to the login window

Whether you are joking with other users, or displaying inspirational text to yourself, or for any other reason, there may be times when you want to put a message in the login window in OS X. Using the terminal, this is very simple. To do this, type the following command:

$ sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText “type your text”

The next time you log out or restart, this message will appear in the login window. Use the following command to remove it:

$ sudo defaults delete /Library/Preferences/com.apple.loginwindow

28. Get Mac talking

You can set your Mac to say whatever you want with the currently selected voice. To do this, use the Say command, such as:

Say “whatever you want your Mac to say”

As soon as you press Return, your Mac will retell the words you typed.

29. Get rid of Dashboard

Let’s be honest, who else uses the Dashboard? For most of us, the only reason it continues to exist is because it appears in Mission Control. If you want to get rid of it completely, use the following command:

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

killall Dock

Use the same command to restore it, but use FALSE instead of TRUE.

30 .Reconstruction of Spotlight

Spotlight is an OS X search tool and is extremely useful. However, sometimes it can break down or not work properly. The solution is to rebuild it. Yes, there is a terminal command for it. Use the following command for this purpose:

sudo mdutil -E /Volumes/DriveName

Here DriveName is the name of the volume you want to index. In most cases, this will be your startup volume, and if you have not changed it, it is called Macintosh HD. On the other hand, if you have Volume mounted on your Mac desktop, you can drag one of the items you want to the terminal window and ignore / Volumes / DriveName.

About the author

Admin

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.