PATH question (newbie)
James Wilkinson
ubuntu at westexe.demon.co.uk
Sun Apr 17 22:47:57 UTC 2005
Matthew S-H wrote:
> How do I change my PATH to include everything in /opt/ ?
*Everything* in /opt? Every last directory and subdirectory? I suppose
you *can*, but I'd advise against it.
I suppose these days the performance benefits are less of a problem,
although they will still be there. [1] It makes the system rather less
predictable: you can't keep an old copy of any package under /opt. And
you can't be sure that you won't get a package with (say) subdirectories
named alpha, i386, itanium, sparc, and x86_64. You'd probably get the
alpha subdirectory in your PATH before the i386, and find you can't run
Alpha binaries [2].
Still want to do it? Here's how to list every file under /opt:
find /opt -type d -xdev
The -xdev stops you going other partitions mounted under /opt. That may
or may not be what you want.
So you could do something like
for i in $(find /opt -type d -xdev)
do
PATH="$PATH:$i"
done
You could put that in ~/.bash_profile, in which case the extra
directories *should* only ever get added to the PATH once (at most). [3]
You could put it in ~/.bashrc, where it gets executed each time a shell
starts. So you'd probably want some sort of test to make sure that you
weren't adding the directories to the PATH twice. You could, I suppose,
do something like
for i in $(find /opt -type d -xdev)
do
echo ":${PATH}:" | grep ":${i}:" > /dev/null || PATH="$PATH:$i"
done
Exercise for readers: what is that test doing and why does it work?
That should work if you *don't* have the current directory anywhere in
your PATH (which is a security problem if you ever mount filesystems
created by untrusted parties without the noexec option). If you must
have the current directory in the PATH, it ought to be at the end.
But, again, some programs leave some sort of setup program around.
They'll all be in your PATH under this scheme, so you'll have to type
(say)
./setup
*anyway* so you have a hope of knowing which program you're running. So
leave the current directory out of your PATH.
By the way: you thought this would be simple, didn't you? There isn't a
predefined recipe to do what you asked for, so we're having to create
one with shell scripting. We've left the realms of "what other people
have done for us", and moved into "do it yourself". The good news is
that you can use this sort of approach for all sorts of problems.
Hope this helps,
James.
[1] You can easily get hundreds of subdirectories under /opt, if you
install much there (and it's the large packages with lots of
subdirectories that tend to get put there). To the best of my knowledge,
on common Linux filesystems, you'll need at least one disk access, maybe
two or more, per directory to check that the file isn't there.
Modern hard disks, if you're lucky, can do about one hundred short
independent accesses per second.
[2] The Alpha, in this case, was designed by the old Digital company as
a very high performance microprocessor. It ditched PC compatibility in
favour of performance: for the markets Digital was interested in, this
wasn't much of a loss.
It was a very desirable processor for Linux and Unix systems, until
Digital was bought by Compaq, Alpha lost its place at the top of the
performance tree, and Compaq killed it.
[3] If you use Gnome terminal, consider Edit -> Current Profile -> Title
and Command -> Run command as a login shell.
--
E-mail address: james | Real people: People who live "out there" in the "real
@westexe.demon.co.uk | world". Politicians at election time are obsessed with
| meeting this exotic species, even though it always
| seems to be surrounded by camera crews and reporters.
| -- BBC News
More information about the ubuntu-users
mailing list