A Mac machine is not only known for its graphical interface and speed, but also for its many powerful utilities, which allow users to save time and perform many different tasks. The terminal is a well-known example of these utilities. The Terminal includes many UNIX utilities and scripts that can perform many actions on your Mac system, such as customizing your Mac system preferences, remotely controlling another Mac, manipulating text files, etc.

The Terminal is a very useful utility for programmers and for users who are familiar with Linux commands. The Mac comes with a number of effective utilities that no other operating system provides, thanks to which you can do much better than just managing the Mac Terminal ad is one of them. In this article, we will discuss some expert Terminal Shell tips and tricks, which can help you improve your daily tasks and make you more productive at the command line.

About the Terminal Shell:

Initially, you need to know how to launch the Terminal utility and where it is located. To find the terminal, you need to go to Applications → Utilities → Terminal. This utility is mostly command-based, so you need to type in specific text strings, then hit the return key to execute them.

  • Interface: After running the Terminal utility, the interface, which you use, is your user's home directory. These directories can be moved by typing cd path/to/other/directory, you can change this path by replacing it with the name of the path to the other directory you want to change. After pressing return, you will be taken to that directory. To exit the terminal, simply type cd ~/, which will immediately take you back to your original directory.
  • Terminal command structure: Terminal commands are divided into three main parts: the first is the command (which is specified), the second is the options (which can change the output of the command), and the third is the argument (which is the specified file or other item for which the command is executed). If you know the basic concepts of command creation, it will be easy to remember them.

Customize your Mac with Terminal:

With this powerful application, you can change the number of preferences hidden by some default commands. Usually, there are too many commands available to perform this task, but here you will be able to see some popular ones. Make sure you have closed the application before changing its default settings in the shell. If you want to undo the entered command, replace TRUE with FALSE after running the same command again.

Disabling the dashboard

With the Terminal shell, you can easily remove your OS X dashboard. Run Terminal and enter the following command:

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

Press return, and you can see the changes immediately. Run the following command to restart the Dock and rid your Mac of the Dashboard function:

killall Dock

If you no longer want the above changes, simply log out of your system and log back in for the changes to take effect.

Disable the Auto-Restore feature

You can easily disable the Auto-Restore feature using the following terminal command

Run the terminal and type the following command:

defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool false

The above command will disable the preview function, to disable this function in QuickTime Player, also type the following command:

defaults write com.apple.QuickTimePlayerX NSQuitAlwaysKeepsWindows -bool false

Now quit and restart the applications and check the change. To undo the change, run the same commands, replacing "false" with "true".

Change the file format of your screenshots

Change the format of your saved screenshots by running the following command in Terminal:

defaults write com.apple.screencapture type extension

Replace the word "extension" with the file extension of your choice in the above command line and press Enter.

Change the default backup periods

Time Machine usually performs a backup every hour after logging on. This is its default function, but you can change it via the Terminal shell. Run it by entering the following comman

sudo defaults write /System/Library/Launch Daemons/com.apple.backupd-auto StartInterval -int 1800

The above command will change the Time Machine backup interval to every 30 minutes. If you want to change it, just replace 1800 with the time interval in seconds (for example, 15 minutes equals 900 seconds).

Delete free space on your Mac


Whenever you delete unwanted files from the space on your Mac, it doesn't provide your operating system with the proper information to mark that space as empty. This data remains on your hard drive and occupies the space until a new data replaces it. Therefore, to solve this problem, you just need to execute a terminal command to erase the existing space beyond recovery. The command is as follows

diskutil secureErase freespace 3 /volumes/drive name

Here you can type the name of your drive using two other commands:

cd /Volumes/

ls

The above command will list all available drives, from there you can copy and paste the path to the required drive into the "drive name" section of the command.

Check for hidden files

To see the full contents of all available folders in the Finder, run the command mentioned below:

defaults write com.apple.finder AppleShowAllFiles TRUE

Always check all files before deleting them, as some of them may belong to the system and any kind of editing or deleting may damage your operating system.

Securing a file or folder

The zip command in the terminal can overcome the security that has the ability to encrypt archived files and folders at once. This encryption power does not meet military or industry standards, but it is surely a good way to protect your data from snoopers.

The command to create an encrypted archive from a folder in the current directory is as follows:

zip -re archiveName name/of/folder


Here you just need to replace name/of/folder with the path and name of the relevant folder and archiveName with the name you want to choose for the zipped file. Run unzip archiveName to recover the contents of an encrypted archive.

Disable the automatic restore feature

 in the Lion/Mountain Lion operating system

Every time you open an application like Preview, all the PDFs you've accessed recently are displayed on your screen. Unfortunately, Mac does not provide a program or command to disable this feature for all applications in the operating system. Therefore, you have to do it for each program. If you want to disable it for the Preview application, follow the command

defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool false

If you want to do the same thing for the QuickTime application, then enter again :

defaults write com.apple.QuickTimePlayerX NSQuitAlwaysKeepsWindows -bool false

Now restart the applications and see the changes.

Customizing file permissions

The terminal command also allows you to decide on file permissions and ensure their privacy and security when sharing. You can solve this problem with two simple commands: chmod and chown.

The chmod command allows you to assign role-based permissions to users other than the owner. Run the following command to allow anyone to open and modify a file,

sudo chmod 777 path-to-file

Simply replace "path-to-file" with the original path and name of the file. This command actually provides full permissions to all users who can access the machine.

To limit the permissions of the file, run the following command instead of the above command:

sudo chmod 644 path-to-file

The above command restricts any type of modification to the file. After running this command, every user can open the file, but cannot modify it, except the owner. You can also change the permission on a file and its complete contents by adding the -R after the command name.

Chown, is used to provide ownership of a file to a specific user. If you do not have access rights to a copied file, run the following command:

sudo chown username path-to-file

Establish a Shell connection for a remote Mac

A terminal session can also be run on a remote machine. Therefore, all commands can be executed on the remote terminal rather than the local terminal. The encrypted connection means that no traffic passes between the two systems.