[SOLVED] How does linux know it's collection of command line programs?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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.
Just in case you are interested, Windows also has a PATH environment variable.
From the cmd:
Code:
echo %PATH%
In UNIX and Linux the PATH is seperator is a colon symbol
In Windows this cannot be used as it forms part of the location and so a semicolon is used instead
what i wanna know is how does linux know all the programs at the command line?
Simply put it doesn't? It's the shell that finds out what commands it has, there are some commands what will be directly run by the shell itself or commands it finds by the environmental variables (ie PATH for Bash), you can do "echo $PATH" to find the currently assigned paths for the shell session, as not all users have the same paths (root has considerably different defaults paths to a normal user).
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.