Durgeshkt 6 months ago
admin #linux

Make your python scripts accessible anywhere in your Linux terminal

Lately, I've been endeavouring to automate some of the basic and mundane tasks I regularly perform on my computer. One task that I aim to automate is the ability to open any of my popular social media platforms (Instagram, Facebook, WhatsApp) with a simple command in the terminal.


After finding the solution to the problem, I encountered another issue: I had to navigate to the script's directory every time I wanted to use it. This process was not only cumbersome but also undermined the automation I sought. Determined to resolve this, I conducted some research online, and here are the steps I followed to make my script globally accessible in the terminal:


First, find the path to the interpreter you are using by typing the following into a terminal:

$ which python3

Next, add the following line at the top of the script file:

#! /usr/bin/python3

(Note: This should be the path to the interpreter displayed by the command in the first step.)

Change your script's permissions with:

chmod u+x socials.py

Now, move your script to the following directory. You need administrator privileges to do this. Type the following command (replace `<directory>` with the desired location):

sudo mv socials.py /usr/local/bin/<directory>/socialscamelCasesnake_case

(Note: You have to remove the file extension if the file has one, and change it to a suitable name using camelCase or snake_case.)

Alternatively, you can create a link to the script without moving the file using the following command:

sudo ln -s /path/to/socials.py /usr/local/bin/socials

References:

1. Linux custom executables are available globally.

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

0
287
Curl Command Cheat Sheet for Penetration Testing

Curl Command Cheat Sheet for Penetration Testing

defaultuser.png
Durgeshkt
6 months ago
Virus and Social Engineering (part 2)

Virus and Social Engineering (part 2)

defaultuser.png
Admin
1 month ago
One liner bug hunting tools

One liner bug hunting tools

defaultuser.png
X0NE
6 months ago
Protect Yourself against Website Server Attacks

Protect Yourself against Website Server Attacks

defaultuser.png
Admin
1 month ago
Metasploit

Metasploit

defaultuser.png
Admin
3 weeks ago