LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-23-2010, 02:03 PM   #1
munyung
LQ Newbie
 
Registered: Aug 2010
Posts: 2

Rep: Reputation: 0
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?
 
Old 08-23-2010, 02:18 PM   #2
ddusza
LQ Newbie
 
Registered: Jul 2010
Location: Indiana
Distribution: Ubuntu 10.04
Posts: 2

Rep: Reputation: 0
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
 
1 members found this post helpful.
Old 08-23-2010, 02:24 PM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
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
 
1 members found this post helpful.
Old 08-23-2010, 02:25 PM   #4
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by munyung View Post
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.
 
1 members found this post helpful.
Old 08-23-2010, 02:27 PM   #5
munyung
LQ Newbie
 
Registered: Aug 2010
Posts: 2

Original Poster
Rep: Reputation: 0
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.

Last edited by munyung; 08-23-2010 at 02:29 PM.
 
Old 08-23-2010, 02:31 PM   #6
ddusza
LQ Newbie
 
Registered: Jul 2010
Location: Indiana
Distribution: Ubuntu 10.04
Posts: 2

Rep: Reputation: 0
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command line programs for Linux? kettuvaloinen Linux - Newbie 3 01-30-2009 10:50 AM
get programs on net from command line brianetilley Linux - Networking 1 12-07-2005 09:42 AM
Running Programs from command line sumguy231 Linux - Software 4 12-17-2004 03:10 PM
launching programs from command line in FS dertien Linux - Software 1 11-26-2004 09:27 AM
Running programs from Command Line SirLostalot Linux - Newbie 1 11-11-2002 09:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration