Why "./myfile" instead of just "myfile"? (to run executable)
Linux - NewbieThis 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!
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.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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.
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.