Inconsistency in bin directories running .sh

When moving my file into /usr/local/bin it wouldn’t run from terminal by typing ‘’ even though it worked in /bin and /usr/bin. echo $PATH gives me this:
So it looks like it should be running but I can’t figure out why it’s not, moving my own binary called main into /usr/local/bin also allowed me to call it from the terminal. It just says: ‘bash: /usr/bin/ No such file or directory’ when I try and call it from terminal, and I did confirm it worked when calling using it’s full file location.

Edit: I also did use chmod +x to make sure it was executable.

You can try hash -r to clear bash’s PATH lookup cache.

I’d also check that the SELinux context is set properly with ls -lZ. Generally, if you make a file in your home directory, you should copy rather than move it into a system directory so that its context is set appropriately for the new location.

1 Like

I don’t really get why, but using cp instead of mv fixed the problem as you suggested. ls -lZ revealed that after using copy instead of move it had root on it instead of my username. I don’t really get what that means though, does it mean it runs as root whenever it runs instead of as my user?.

No, it just means the file is owned by root. When you copied it you made a new file, which is owned by root because the copy was done as root.

Oh, I see. So files need to be owned by root to run from the path? Anyway, thanks for the help.

It’s not strictly necessary, but it’s good practice for files in system directories to be owned by root.

More important is the SELinux context. A file created in /usr/local/bin will have system_u:object_r:bin_t:s0, whereas something created in your home directory might have unconfined_u:object_r:user_home_t:s0. That context stays with the file when it’s moved, and so some confined system services may not be able to access it.

None of this should have prevented access by your own user, but it’s still prudent to make it correct.