Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

One thing that puzzles me about desktop Linux, at least, is that just about everything is in my PATH. By everything, I mean every desktop application, including things like gnome-character-map and glchess. These have no command line interfaces to speak of, so I can't think of a case where I would be regularly launching these from a terminal - and, within that unlikely case, I can't imagine being inconvenienced by needing to type their full paths. It just seems cluttery, but maybe there's a good reason.

So, why does this happen? Is there any noteworthy impact on performance or maintainability?

share|improve this question

2 Answers 2

up vote 14 down vote accepted

All the commands that a user might want to run are in the PATH. That's what it's for. This includes commands that you run directly, commands that other people run directly, and commands that you or other people run indirectly because they are invoked by other commands. This is not limited to commands run from a terminal: commands run from a GUI are also searched in the command search path (again, that's what it's for).

Needing to type the full path would be terrible: you'd need to find out what the full path is! You'd need to keep track of whether it's in /usr/bin (which contains most programs shipped with the operating system), or in /usr/local/bin (which contains programs installed manually by the administrator, as well as programs that aren't part of the core OS on some unix variants), or in some other system-specific directory, or somewhere in the user's home directory.

It's difficult to answer about the “impact on performance or maintainability” because you don't say what you're comparing it to. If you're comparing with having to type the full path everywhere, that's a nightmare for maintainability: if you ever relocate a program, or if you want to install a newer version than what came with the OS or was installed by a system administrator, you have to replace that full path everywhere. The performance impact of looking the name in a few directories is negligible.

If you're comparing with Windows, it's even worse: some programs add not only the executable, but also all kinds of crap to the PATH, and you end up with a mile-long PATH variable that still doesn't include all programs, because many programs don't add themselves to the system PATH when you install them.

share|improve this answer
    
That looks like pretty rational rationale. Thank you for the explanation! The bit about replacing a program makes a lot of sense. I hadn't thought about that at all :) The part that strikes me about it is I like to have small and descriptive namespaces when I think about programming, while here everything is sort of in the same global namespace (and, when we do look at full paths, in quite nondescript places like */bin). I guess they are pretty different things, though. –  Dylan McCall Aug 16 '12 at 5:12

The PATH variable contains a list of directory paths. When the user types a command without providing the full path, this list is checked if it contains a path that leads to the command. There's nothing inherently terminal or command-line specific about it.

Moreover there's nothing Desktop Linux specific about it either. The PATH from my XP system contains %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem which probably covers most of Windows's binaries.

The directories in PATH are searched in the order specified and stop as soon as a match is found. System directories are usually at the beginning to give them the highest precedence. Users should append custom search paths at the end.

As for performance: Most modern shells cache the contents of PATH so they don't have to scan the disk every time the users enters a command.

share|improve this answer
    
The Windows PATH covers most of the binaries that ship with Windows, but ordinary applications you install aren't normally found in the PATH. (Well, apps with a command-line component will add themselves to PATH, but GUI-only ones normally don't.) –  cjm Aug 15 '12 at 23:13
    
Cool, I always contemplated the order and its significance. How about a rule of thumb? I have (almost) every combination of usr, local, bin, and sbin (excluding my user home directory). –  Emanuel Berg Aug 16 '12 at 4:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.