Last Updated : 12 Jul, 2025
In Linux, there is a way to execute python files from anywhere. This can be done by typing several commands in the terminal.
Prerequisite: Steps:cd ~
mkdir check cd check touch file1.py
import os
i = 1
# Write the path where to create the directories
path ="/home / dev / test/"
try:
while i<5:
os.mkdir(path+"file"+str(i))
i+= 1
except OSError:
print("File creation failed !!")
This script will create 4 directories in the specified path.which pythonFor python 3
which python3
/usr/bin/python3
then write the below command in the starting of the script.
#!/usr/bin/python3So the python script would look like Python3 1==
#! usr / bin / python3
import os
i = 1
# Write the path where to create the directories
path ="/home / dev / test/"
try:
while i<5:
os.mkdir(path+"file"+str(i))
i+= 1
except OSError:
print("File creation failed !!")
pwdLet it be
/home/usr/check
$PATH
variable. For this type in terminal
sudo nano .bashrcBefore this command make sure that you are in the home directory. Then add this line in the file
export PATH=$PATH:/home/dev/checkThis will get added to the path variable. Then type
source ~/.bashrc
file1.py
This will create the four directories in the check folder. Now any python file placed in the check directory we can be executed from anywhere in the terminal by typing the file name.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4