Skip to content
Advertisement

Would it be wrong to store custom .py scripts in a personal Linux directory?

My end goal is simple: Store a set of .py scripts on my Linux system such that I can:

  • Run them from the command line without using /Python [name]
  • Edit them easily

I can fix the first issue by storing the scripts in /usr/local/bin/

This causes the second issue, because now when I attempt to open the script for editing purposes, I am denied permission. I can partially fix this issue by using /sudo vi [name], which is a disappointing fix because who wants to code in vi?

So I either want the ability to read and write scripts in /usr/local/bin/, or I need the ability to store the scripts elsewhere yet still have them accessible from the command line.

My current (broken*) fix is to store them in a personal directory located somewhere in my home directory, which is added to my path. I have heard this is terrible style however. Thoughts?

*I am currently having trouble adding a personal folder to the PATH. This is content for another question however .

Advertisement

Answer

There is another alternative, place your python files in /home/{your_name}/bin . /home/{your_name}/bin is typically included in distro’s default paths, which bypasses the issue you are having regarding being unable to edit your path.

If that is not an option you could edit the permissions of the directory /usr/bin, but that is a bad idea from a security standpoint. (SRC: https://unix.stackexchange.com/questions/37724/permissions-ownership-of-usr-local-bin#37726 )

Another option you have is to give your default program which you edit files with sudo permissions. So you could do /sudo xdg-open file_name if the default way you open python files is the editor, or you could do /sudo editor_name file_name if it is an editor which by default opens another the file in its gui.

Ultimately though, fixing the issue with your path and editing it is probably your best solution to avoid giving unnecessary permission to files.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement