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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
09-13-2007, 06:54 AM
|
#1
|
LQ Newbie
Registered: Sep 2007
Posts: 6
Rep:
|
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 !
|
|
|
09-13-2007, 07:21 AM
|
#2
|
LQ Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,337
Rep:
|
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 
|
|
|
09-13-2007, 07:56 AM
|
#3
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
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.
|
|
|
09-13-2007, 08:08 AM
|
#4
|
Member
Registered: May 2004
Location: Tampa, Fl
Distribution: Arch
Posts: 648
Rep:
|
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...
|
|
|
09-13-2007, 08:53 AM
|
#5
|
Member
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642
Rep: 
|
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 09:22 AM.
|
|
|
09-13-2007, 09:31 AM
|
#6
|
Member
Registered: Dec 2006
Distribution: Debian (Wheeze)
Posts: 391
Rep: 
|
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.
|
|
|
09-17-2007, 05:24 AM
|
#7
|
LQ Newbie
Registered: Sep 2007
Posts: 6
Original Poster
Rep:
|
thanks to all for solving my query...
|
|
|
All times are GMT -5. The time now is 10:09 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|