DEV Community

clinton wambugu
clinton wambugu

Posted on

Make your python script accessible anywhere in your linux terminal

Image banner
Recently I have been trying to automate some of the basic and mundane task that I do on my computer. One of the task that I wanted to automate was opening any of my the popular social media platforms(Instagram, facebook, whatsapp) on the web by typing a simple command on the terminal.
The problem after coming up with the solution was that I had to go to the directory every time I wanted to use the script. This was not only cumbersome but also defeated the point of my automation so I did a little digging on the web and here are the steps that I took to make my script application globally accessible in the terminal:

  • First locate the path for the interpreter you are using by typing the following in the terminal:

$ which python3

  • Add the following line at the top of your script file:

#! /usr/bin/python3

-this is the path of your interpreter displayed by the command in the first step.

  • Change your scripts permission with the following command:

chmod u+x socials.py

  • Move your script to the following directory: /usr/local/bin/. You will need admin access for the operation to be successful.Type the following command sudo mv socials.py /usr/local/bin/socials . You will have to remove the file extension and if the file has camelCase change it to snake_case
  • Alternatively you can create a link to your script without having to move your file by using the following command:

sudo ln socials.py /usr/local/bin/socials

References:

  1. Linux custom executable globally available
  2. How to make a globally available executable script in the scripting language of your choice

Top comments (0)