How does linux know it's collection of command line programs?
Hey guys, i just started using ubuntu after being a long time windows user.
what i find really interesting is that in command line, i can type many programs and commands, eg firefox can be run via command line from anywhere. In windows cmd prompt, im used to having to run the .exe file by first navigating to it, then being able to run the .exe. what i wanna know is how does linux know all the programs at the command line? |
The simplest answer is that in Linux (and UNIX as well), there is an environment variable "PATH" which has a list of where many of the programs/scripts you run are located. You can see what your PATH variable is set to by typing the command "echo $PATH" at the command prompt. Here is an example:
ddusza@warlock:~$ echo $PATH /home/ddusza/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/ddusza/bin The order is also somewhat important as it means the command will be searched for in the directory locations in order (from the sample PATH above): /home/ddusza/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /home/ddusza/bin In the case of firefox from your post, firefox is located in /usr/bin--which is where it gets executed from. If you try to run something which isn't in your PATH, it will typically come back with a "not found" error message. You can also add and remove directories from your PATH variable on the command line and in your .bashrc/.cshrc/.profile, depending on what shell you are using. Hope this answers your question. Don |
Just in case you are interested, Windows also has a PATH environment variable.
From the cmd: Code:
echo %PATH% In Windows this cannot be used as it forms part of the location and so a semicolon is used instead |
Quote:
As far as the OS goes, it's the layer that supplies the middle ground between the hardware and the software... so "Linux" as in the Kernel does not know what's being run, or what it's doing, it just runs it... I guess that's a simplistic way to put it. The shell is what knows where commands are. |
awesome, this was the answer iv been looking for for days!
$PATH is something completely new to me, i guess i should be doing some reading on this then. thanks don! *edit* whoah fast replies, thanks guys. learned something new about windows too. |
No problem. In case you are really feeling daring, you can also issue the command 'env' at the command prompt, which will list out all of the defined variables in your shell environment.
Don |
All times are GMT -5. The time now is 03:16 AM. |