Welcome to the most active Linux Forum on the web.
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 09-13-2007, 07:54 AM   #1
LQ Newbie
Registered: Sep 2007
Posts: 6

Rep: Reputation: 0
why executables are executed through ./ only

i have a executable file 'test.out'
i go to the directory containing 'test.out', and type

$ test.out

the program dosen't run, but when i type

$ ./test.out

it works. Why does we need ./ to run the file.
I know './' is current directory. i need to know some other reasons !
Old 09-13-2007, 08:21 AM   #2
Mega Man X
LQ Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 64
It could avoid conflict with other programs on your path. For example, you have a program called potato on your path and if you just type potato, you'd fire up the one on your PATH, when you actually want to fire your own potato... for example
Old 09-13-2007, 08:56 AM   #3
Wim Sturkenboom
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Wait till you write your own app to wipe you HD and call it ls. Now you login as root, go to your directory and run ls expecting to get a directory listing. Bingo.

You will probably not call that app ls, but someone with bad intentions will.

The 'problem' might depend on your distro. For a root user in Slackware the current directory is not in the path (see above security risk), for a normal user it is.
Old 09-13-2007, 09:08 AM   #4
Registered: May 2004
Location: Tampa, Fl
Distribution: Arch
Posts: 648

Rep: Reputation: 30
I thought for general security purposes the current directory was never included into the path. It is one of the few ways, as you said, that can create wonderful security loopholes and whatnots. I do know there is a way to add the current directory into the path, but I would avoid doing that, just in case...
Old 09-13-2007, 09:53 AM   #5
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
Here is how you do it. But do so at your own risk.

export PATH=$PATH:.

This will allow you to run programs or scripts without typing ./

This effect is temporally, once you logout the effect is gone.

For permanent effect, see below

For bash shell global environment, as root edit the /etc/profile or bash_profile script. Look for something like this:

An example

export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/X11R6/bin:/opt/bin:"

Add a period at the end, like so

export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/X11R6/bin:/opt/bin:."

The period means current directory.

Two ways to take effect, type source /etc/profile or
logout and login again.

A safer way is create a directory for your programs or shell scripts, for example bin

Add the directory to your PATH environment like so

export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/X11R6/bin:/opt/bin:$HOME/bin"

Logout and login again.

Now you can run your scripts anywhere from your home environment, no need to be in the current directory.

Last edited by dv502; 09-13-2007 at 10:22 AM.
Old 09-13-2007, 10:31 AM   #6
Registered: Dec 2006
Distribution: Debian (Wheeze)
Posts: 391

Rep: Reputation: Disabled
The dot slash parameter in front of the program and or file name tells the kernel to execute the sequence of commands stored in the script and or file that you amend to the end of the aforementioned command line interface (CLI) argument.
Old 09-17-2007, 06:24 AM   #7
LQ Newbie
Registered: Sep 2007
Posts: 6

Original Poster
Rep: Reputation: 0
thanks to all for solving my query...


executables, programming, running

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
When .bashrc is executed? SeRGeiSarov Programming 4 07-31-2007 01:40 PM
how to see which command has been executed ? Volcano Linux - Newbie 4 12-11-2006 09:48 AM
How to get next executed line phuna Programming 2 07-08-2005 01:05 AM
.bash_logout does not get executed nearfar Linux - Newbie 3 10-17-2003 12:40 PM
.xinitrc isn't executed hampel Linux - Software 5 08-06-2003 04:53 AM > Forums > Linux Forums > Linux - Newbie

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

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