Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-20-2005, 02:22 PM   #1
LQ Newbie
Registered: Apr 2005
Posts: 2

Rep: Reputation: 0
Question about running programs with ./

Hello, new to Linux so Pardon My Ignorance.....

I've noticed that some programs aren't "found" when I run them, unless I run them like this:

$ ./myprogram

For example, if I have a program in /usr/programs/myprogram, and I do this:

$ cd /usr/programs
$ myprogram

It gives me an error that it can't find myprogram.
But if I run it like this:

$ cd /usr/programs
$ ./myprogram

It runs. This only seems to happen with some programs. Anyone know why this is?
Old 04-20-2005, 02:30 PM   #2
Senior Member
Registered: Mar 2005
Location: Las Vegas, NV
Distribution: Mandriva Slackware FreeBSD
Posts: 1,468

Rep: Reputation: 48
It is a script file. ./myprogram

cat ./myprogram
to see script contents.

Old 04-20-2005, 02:51 PM   #3
Registered: Mar 2005
Location: USA
Distribution: Kubuntu Breezy
Posts: 79

Rep: Reputation: 15
Yes, the way Linux manages executables is much different than in MS-DOS (I'm assuming that this is where you're coming from). In Linux, you can only execute commands that are in certain directories, such as /bin, /sbin, /usr/bin. These directories are contained in the PATH variable. You can see this list by typing:

$ echo $PATH

This makes it very easy to execute commands from wherever you are in the directory tree without having to cd to the directory that contains the executable, or having to type out the whole path name. If you want to execute a command that is not in one of these designated directories, you have to type the absolute path name (eg /usr/program/myprogram or ./myprogram, if you are in /usr/program already). While this might seem like an inconvenience, it prevents you from accidentally executing files in the current directory when you really wanted to execute a generic system command. For example, it prevents someone from creating a trojan named "ls" which would be run whenever you wanted to use the ls command. It also prevents commands from behaving differently depending on which directory you are in.

Hope that helps,

Old 04-20-2005, 04:37 PM   #4
LQ Newbie
Registered: Apr 2005
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks so much for the answer! I've been reading about Symbolic Links, which is another new topic that seems related.
For example, when I installed firefox I put it in /usr/firefox. To run the firefox program, rather than adjusting the PATH variable to add /usr/firefox or having to cd /usr/firefox and then run ./firefox, I could create a symbolic link in /usr/bin for firefox?
Old 04-20-2005, 06:16 PM   #5
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,907

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
You could edit your user .bashrc or .bashrc_profile (different distros have different names for it) to add an alias. Such as: alias firefox="/usr/firefox". Then, everytime you boot up, the command is available to you by simply typing firefox and pressing enter.
To make such an alias available to all users, edit the /etc/bashrc to add the alias there. Be adivsed that, on upgrading your distro, the system bashrc may be overwritten, in which case you could loose all of your aliases. In other words, keep a backup copy, which you can then cut and paste your aliases into a changed bashrc.
Old 04-20-2005, 07:13 PM   #6
Senior Member
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
You can always change your PATH variable though. For example, if you wanted to have a bin directory in your home, you would add the following line to .bash_profile:
export PATH=$PATH:/home/iball/bin
If you want to be able to execute programs in the current directory, (NOT generally a good idea, ,particularly for root), add the following line to .bash_profile
export PATH=$PATH:.
I hope this helps


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
Running Programs Slayer097 Linux - Newbie 3 02-23-2005 04:43 PM
Question about installing and running programs BRoscoL Linux - Newbie 6 05-24-2004 01:56 PM
Choppy sound when other programs running + mouse and login question (tm) Linux - Newbie 6 03-24-2004 09:57 AM
Running programs? BajaNick Linux - General 10 07-07-2003 09:56 PM
Help on Running Programs mooreted Linux - Software 3 05-16-2003 10:32 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:36 PM.

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