I go to /usr/local/bin and do a dir. Nothing there, so I try to open a new file there. Refused. I try altering permissions. Refused.
I have a now-working .py script in another directory. How can I move it to /usr/local/bin, please?
Code: Select all
pi@pidrive:~ $ echo $PATH
/home/pi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
pi@pidrive:~ $ ls bin
k2 k80 kx kxs kxs2 play qx runclock startkdfc xxx
Thank you .I used your directions to move my script tp /usr/local/bin and it shows that directory as being on the $PATH already, and the script's permissions there to be owned by pi but none of the options under 'Open' allow me to launch the app, though I can still do it if I bring up terminal and enter python3 v3.py (the script's filename). I haven't tried your 'opening' a /home/pi/bin yet because previous advice said to use /usr/local/bin (which IS on the path already), mainly because I'm lost in a welter of what seems to be conflicting needs. If you or anyone can bear with me and put me right, I'd be grateful.W. H. Heydt wrote:I don't recommend doing it, but the problem isn't permissions. It's ownership. Move your file by using "sudo mv <filename> /usr/local/bin".
However, a far, far better solution would be to create a 'bin' directory in your home directory--e.g. /home/pi/bin--and put your executable file there. After relogging, your own ~/bin directory will be in your path and you can execute it from anywhere. Here's an example on one of my Pis...Code: Select all
pi@pidrive:~ $ echo $PATH /home/pi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games pi@pidrive:~ $ ls bin k2 k80 kx kxs kxs2 play qx runclock startkdfc xxx
Why?W. H. Heydt wrote: a far, far better solution would be to create a 'bin' directory in your home directory--e.g. /home/pi/bin--and put your executable file there.
I agree. But, FWIW, I do usually go the ~/bin route myself.achrn wrote:Why?W. H. Heydt wrote: a far, far better solution would be to create a 'bin' directory in your home directory--e.g. /home/pi/bin--and put your executable file there.
Why is a user-specific bin directory better? I'm struggling to see any benefit - other users won't be able to execute a file put there, and if there are no other users then what's the problem with using the system directory? A user-specific bin directory is not, to my mind, equivalent to the /usr/local/bin directory, and a file that should be in the latter will not behave equivalently in the user specific bin directory. I don't see it as 'better' at all, let alone 'far far better'. What are your reasons for considering it better?
Indeed, but if you're going to put a non-standard entry into the PATH, you don't need to put the file anywhere special - the OP could have left their file wherever it was and just edited PATH - so that's not a solution to the question I perceived being raised. I think that's an inferior solution anyway - you'd end up with a very long PATH if you updated it for every random place you'd created a script.Martin Frezman wrote: Note, incidentally, that it is not really true to say that other users (if there are any) can't execute the program if it is in ~pi/bin. They just have to have ~pi/bin in their PATH (or, of course, use a full path to execute it).
If you had ever managed a properly set up multi-user Linux/Unix system you would know that that is not true.Martin Frezman wrote: Note, incidentally, that it is not really true to say that other users (if there are any) can't execute the program if it is in ~pi/bin. They just have to have ~pi/bin in their PATH (or, of course, use a full path to execute it).
The executable in question belongs to user 'pi'. Therefore, it belongs in a directory owned by 'pi'. If it is to be a generally used program, then it would belong in a system owned directory and should have the executable file ownership changed to 'root'.achrn wrote:Why?W. H. Heydt wrote: a far, far better solution would be to create a 'bin' directory in your home directory--e.g. /home/pi/bin--and put your executable file there.
Why is a user-specific bin directory better? I'm struggling to see any benefit - other users won't be able to execute a file put there, and if there are no other users then what's the problem with using the system directory? A user-specific bin directory is not, to my mind, equivalent to the /usr/local/bin directory, and a file that should be in the latter will not behave equivalently in the user specific bin directory. I don't see it as 'better' at all, let alone 'far far better'. What are your reasons for considering it better?
That's not what I'm saying.Martin Frezman wrote:I don't doubt that you can handle and fix the problems as they come up.
But most users can't/won't.
The largest multi-user UNIX system I have administered had only about 100 active user accounts, so maybe yours really is bigger than mine, but I'm still not understanding why you know that putting the executable into the user directory is a 'far far better' solution.W. H. Heydt wrote: The executable in question belongs to user 'pi'. Therefore, it belongs in a directory owned by 'pi'. If it is to be a generally used program, then it would belong in a system owned directory and should have the executable file ownership changed to 'root'.
Bear in mind that at any time, an upgrade to the system could rebuild any system owned directory and you would have to re-install anything you had put there. An upgrade shouldn't touch account owned directories, such as ~/bin.
It is quite possible that my opinions on this are driven by having used and worked on unix systems that had multiple *active* user accounts and I tend to think in terms of larger systems than Pis. I would maintain, though, that it is good practice to treat Pis that way as a matter of habit and not get into a habit that might cause problems should one eventually find oneself working with larger, production, systems.