LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 03: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, 03: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, 03:24 PM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
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, 03:25 PM   #4
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 5.4, Mac OS 10.4 (tiger)
Posts: 1,005

Rep: Reputation: 79
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, 03: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 03:29 PM.
 
Old 08-23-2010, 03: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 11:50 AM
get programs on net from command line brianetilley Linux - Networking 1 12-07-2005 10:42 AM
Running Programs from command line sumguy231 Linux - Software 4 12-17-2004 04:10 PM
launching programs from command line in FS dertien Linux - Software 1 11-26-2004 10:27 AM
Running programs from Command Line SirLostalot Linux - Newbie 1 11-11-2002 10:24 PM


All times are GMT -5. The time now is 07:07 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration