iCloud Terminal

If you often run the same script repeatedly, it can become tedious to type out the full path each time. A great way to streamline your workflow is to add custom commands to the terminal. This not only saves time but also enhances productivity, especially for developers and system administrators.

Getting Started with Custom Commands

To add custom commands to the terminal, you have two primary methods:

1. Place Command Files in Directories Already in Your $PATH:

  • The $PATH environment variable contains directories where the system looks for executable files. By placing your script in one of these directories, you can run it from anywhere.

2. Add an Easily Accessible Directory to Your $PATH:

  • If you’d prefer a more accessible directory to keep custom commands organized, I’d recommend creating a “bin” folder in your home directory to follow system standards.

Accessing Commands as Root

If you need to access your custom commands while using root privileges, you’ll want to edit the /etc/paths file:

sudo nano /etc/paths

NOTE: ~ is not supported, so use the absolute path like /Users/[USERNAME]/bin.

Organize Commands for Flexibility

If you only want some of custom commands to be accesible to the root user, you can add two directories to your $PATH:

  • One via the /etc/paths file for system-wide commands.
  • Another through your shell’s rc file, for personal or sandboxed commands.

Related Articles:

You can learn more about the $PATH variable, and how to edit to it here.

Conclusion

By following these steps, you’ll easily be able to add custom commands to the terminal, streamlining your daily tasks and potentially boosting productivity.

I hope this article provided you with what you were looking for. If you have any feedback, please leave a comment.

Credits

  • Apple – The system used for this article.