0

I recently started to put all my dotfiles in a VCS, and just for complete organization, I thought of creating a personal "usr" folder, as in a folder within the home folder that gets "merged" with the usr directory whenever looking up commands in PATH or even man pages. Now for the questions:

  1. Is there any reason I shouldn't be doing this? Are there any downsides I'm not seeing, or better alternatives?
  2. If there aren't any downsides, how could this be achieved?

I already know of this question, but from what I understand the top answer suggests an option that would actually put files in /usr, while I would prefer a method similar to adding a folder to PATH, it doesn't actually move any files it just looks for them in different places.

I also looked into overlayfs, but it looks like it runs on boot. While it might be faster, I would prefer that my files are merged when I login.

2

2 Answers 2

2

Do once:

cd
mkdir -p usr/bin usr/man

Add to your ~/.profile or other shell initialization file:

PATH="$PATH:~/usr/bin"
MANPATH="$MANPATH:~/usr/man"

... and then put things into those directories.

Notes:

  • The PATHs are searched from left to right. If you have developed a program called robot, the order may not matter much.  If you have developed a program called cat, and you want to run it instead of /bin/cat, then you will need to put ~/usr/bin ahead of /bin in $PATH; e.g., by

    PATH="~/usr/bin:$PATH"
    

    Note that this can represent a security risk.  If you do this, and an attacker can get write access to your home directory, he can leave a Trojan Horse in your ~/usr/bin directory and take over your account.

  • If you want to get fancy, you can look at the current value of $PATH and put ~/usr/bin somewhere in the middle.  This may be harder to maintain.
  • While there's nothing serious wrong with the above, you might prefer to use ~/bin instead of ~/usr/bin.  In fact, depending on what system you have, you just might find that ~/bin (a.k.a. $HOME/bin) is already in $PATH by default.
4
  • 1
    On some operating systems, such as Ubuntu for example, the shipped shell profiles will already do that in fact, with $HOME/bin.
    – JdeBP
    Jul 21, 2017 at 6:55
  • @JdeBP: Good point; I added it to the answer. Jul 21, 2017 at 7:02
  • There are also a few distros that have this kind of concept inherent in the package manager (on NixOS for example, packages can be installed into profiles, and users can create, switch, and manage their own profiles at will). Jul 21, 2017 at 11:54
  • The man part was only one example, not all programs allow the path to be changed. A preferred solution would be to somehow merge the two folders without the need to modify any paths.
    – jotch
    Jul 21, 2017 at 15:45
0

That's what the whole /usr/local structure is for. /usr is meant to be managed by the systems package manager except for /usr/local where the system administrator can add custom stuff.

It is even likely that /usr/local/bin is already in PATH.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .