Help answer threads with 0 replies.
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 06-12-2006, 12:20 AM   #1
LQ Newbie
Registered: Oct 2005
Location: Queensland, Australia
Distribution: Solaris
Posts: 14

Rep: Reputation: 0
Question Why "./myfile" instead of just "myfile"? (to run executable)

I am often creating new executables as I am brushing up on my C++, but it is annoying to always have to type "./executable" instead of just "executable" to run the newly compiled program.

Is there any way to change your new executables so that you don't have to type './' in front of it all the time? (I could modify makefile to do this after compiling)

Thanks in advance...

P.S. I use Fedora core 4 if that makes any difference
Old 06-12-2006, 12:32 AM   #2
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,289

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
The ./ (. is the current directory and / is the path separator) refers to the current PATH. Unlike Windows, in *nix systems the current directory is not part of the executable search $PATH in the shell, so it must be specified explicitly. You can add . to the end of your PATH (search around here for details -- it's been discussed many times), but you shouldn't do this to the root user for security reasons, and certainly don't put . anywhere in your $PATH but last, otherwise someone could create a malicious file with the same name as a common binary and trick you into running it.
Old 06-12-2006, 01:01 AM   #3
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740
You can put executables in a directory which is in PATH, or you can add a directory to PATH. If you are doing a lot of this, then just make a special directory which is in PATH.

in HOME: mkdir bin
export PATH="$PATH:~/bin"

to make this permanent, you may also need to edit your startup files
Old 06-12-2006, 01:22 AM   #4
LQ Newbie
Registered: Oct 2005
Location: Queensland, Australia
Distribution: Solaris
Posts: 14

Original Poster
Rep: Reputation: 0
aahh! That makes a lot of sense... I can handle that.

Thanks guys!
Old 06-12-2006, 03:22 AM   #5
Registered: Oct 2005
Location: Rhode Island, USA
Distribution: Slackware, Xubuntu
Posts: 348

Rep: Reputation: 32

This thread brought back memories...

I first started to learn unix command line as a required class in college (Introduction to Unix/Linux). Our professor was an "aged" man who basically started using Unix when it first became popular in the early 70s. He worked as a network administrator until about 8 years ago when he decided to start teaching... and is a consultant to the school's network. When we were learning the UNIX environment, we went over the whole search path thing and executables. As part of our exercises, we made a bin directory in our home folder and all our scripts were to be put there and nowhere else. What makes me smile about this thread is one of my classmates simply asked the question about why not put the current directory in the search path rather than always use ./ or putting the script in "that bin directory." This spawned a 20 minute lecture about all the potential security risks that could arise from doing something like that. One thing he mentioned (which I might not explain perfectly) is that if someone wanted to install malware or rewrite a command and make it do something malicious, it would be so much easier if the current directory were in the search path. We also got the bonus story of how he had to fire an underling for consistently using the current directory in the search path. Anyway... it all boiled down to the idea that if something is supposed to be executable, then it should be in a directory dedicated to executables so the administrator can track them. If you're in the habit of making executables, then by all means it's just damn safe to make a ~/bin directory and add it to your search path. When I first got Slackware and experimented with it, I was a little taken with the current directory being in my search path. It was one of the first things I got rid of because I'm so deep in the habit of using ~/bin. Sorry if my story bored you... but I figured I would share my experience and endorse the ~/bin option.
Old 06-12-2006, 04:05 PM   #6
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179
It's a deliberate step intended to make sure that, if you find yourself executing a program that's in your current-directory, then you know that you are doing so. Otherwise, someone could "slip" a rogue program into your current directory, masquerading as a commonly-used command.

Anyway, "it was done on-purpose."
Old 06-12-2006, 05:00 PM   #7
Registered: Jun 2006
Distribution: SuSe
Posts: 66

Rep: Reputation: 15
Have you ever typed the set command in a terminal window? That's some pretty crazy stuff right there!
Old 06-12-2006, 09:17 PM   #8
LQ Newbie
Registered: Oct 2005
Location: Queensland, Australia
Distribution: Solaris
Posts: 14

Original Poster
Rep: Reputation: 0
Thumbs up

Thanks Zetabill - it's kinda funny that a guy got fired for adding the current directory to the search path though... (was probably a windows-user )

I think I'll take ur advice and make a ~/bin directory, and my makefiles can simply chuck the executable in there.

Thanks again all!

Now I know more about that wonderful OS that is Linux; mmm... feel the power...


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
what is "sticky bit mode" , "SUID" , "SGID" augustus123 Linux - General 10 08-03-2012 05:40 AM
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 12:26 PM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 04:07 PM
boot record backup "dd if=/dev/hda1 bs=512 count=1 of=myfile" csDraco_ Slackware 4 04-20-2003 02:10 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:05 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