lazyhacker 2 years ago
Illusion #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
2.1K
Sorcery   HTB Writeup | HacktheBox | Season 8

Sorcery HTB Writeup | HacktheBox | Season 8

https://lh3.googleusercontent.com/a/ACg8ocIkM8EGIx0gz9GUP_nM6_sMxivr6876Wp0e9MAp6mGc=s96-c
xone
2 months ago
HTB CAPE Preparation Guide: A Detailed Roadmap for Success

HTB CAPE Preparation Guide: A Detailed Roadmap for Success

defaultuser.png
lazyhacker
2 months ago
ERA  HTB Writeup | HacktheBox | Season 8

ERA HTB Writeup | HacktheBox | Season 8

https://lh3.googleusercontent.com/a/ACg8ocIkM8EGIx0gz9GUP_nM6_sMxivr6876Wp0e9MAp6mGc=s96-c
xone
1 month ago

Black Box Testing

https://lh3.googleusercontent.com/a/ACg8ocIkM8EGIx0gz9GUP_nM6_sMxivr6876Wp0e9MAp6mGc=s96-c
xone
1 year ago
XSS Challenge Game Answers and Analysis Level 1-18

XSS Challenge Game Answers and Analysis Level 1-18

https://lh3.googleusercontent.com/a/ACg8ocIkM8EGIx0gz9GUP_nM6_sMxivr6876Wp0e9MAp6mGc=s96-c
xone
4 months ago