LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What does ./ do? (https://www.linuxquestions.org/questions/linux-newbie-8/what-does-do-272073/)

Super Nade 12-30-2004 05:53 PM

What does ./ do?
 
Hello all (N00b here),

I have looked through many books and also googled for information but I can't find the answer to this question:

What does ./ do?

This came up when I was trying to install Mathematica on my Mandrake 10.1 beta system.

-The instructions said I must login as root, so I did a su root.

-Next, I did cd /mnt/cdrom/Unix/Installer

-I found the file MathInstaller displayed in green with a star after it. So I typed in MathInstaller at the prompt. I got an error message saying command not found. So, somehow I did a ./ MathInstaller and it worked!

So should I always do a ./ to run green files?

I am overwhelmed by the amount of sttuff that needs to be known to work with Linux. Could somebody point me to a site with basic information for N00bs like me?

Thanks in advance!

S.N

speel 12-30-2004 06:03 PM

./ is usually used to run certian files thats all and what kinda basic stuff you want to know? like basic commands and things like that?

amfoster 12-30-2004 06:05 PM

type
echo $PATH

That will show you a colon delimited list of directories where you can execute code by just typing their name. Note that the directory you were not in was not in that path statement. Thus, you must declare the full path to the program you are going to run.

. is a shortcut relating to the directory you are currently in.

.. is the directory just above you. (parent directory)
so by saying ./programname, you are giving the path to the command.

Most regular users will have :. at the end of their path. That way no matter what dir they are in, they will have that as their path to execute applications.

The root account rarely has that as he/she may type something accidently in a directory and execute it if there happens to be an executable with that name in the dir. It is a little safety net.

Note: roots path is far different from a regular users. He/she has a lot of sbin directories listed that a regular user doesnt.

Root can type ifconfig to see the network IP address, where as a regular user would have to type /sbin/ifconfig

I think that shud explain it fairly well for you.

kevinatkins 12-30-2004 06:21 PM

hi,

your question is best explained as follows, and applies to running commands from within a shell (or command-line environment, eg, konsole)...

executable programs and / or scripts can be found in various locations on your system. the most common places are /usr/bin; /usr/local/bin; /usr/sbin, and so on. these can be considered 'default' locations. now, say you've got a program or script called 'myprogram' located in /usr/bin. to run it, you could type '/usr/bin/myprogram'. but since /usr/bin is such a common location for programs, it would be nice if you didn't have to type in '/usr/bin' every time... this is why environment variables are used, and what this means is that if you just type in 'myprogram', the system will look at all of the 'default' locations, and find the file you want to run.

however, executable programs aren't always found in the 'default' locations - you might have an executable script in your /home directory. in these situations, you prepend ./ to the filename - this tells the system that the file you want to run is located in your current working directory, and prevents the system from assuming that the file is in one of the 'default' locations (where the file would, of course, not be found)..

hope this helps.

Super Nade 12-30-2004 11:27 PM

Thanks guys,

I do comprehend the importance of having a safeguard as root and hence the ./
Please tell me if my understanding is right in this context:-

- I'm logged in as root.
- Both /usr/bin and /mnt/cdrom have the same name executable file "myprogram" but I want to run the one on the cd.
- The ./ safeguard will ensure that I run the one on the cd only.

Why should Linux even have a default path list? Wouldn't it be easier just to run the file as $ cd /mnt/cdrom/myprogram ?

I come form the Windows world and hence the question :)

whipermr5 12-30-2004 11:33 PM

Quote:

Why should Linux even have a default path list? Wouldn't it be easier just to run the file as $ cd /mnt/cdrom/myprogram ?
Then you have to type the whole path, which is quite tedious! For example, if you wanted to run the command "lilo", you would have to type /sbin/lilo every time, so if you have a path, you just type "lilo".

Super Nade 12-31-2004 12:05 AM

O.K that makes sense now.

Another N00b Q:
When I double-clicked the file from a root X-Window, nothing happened. Why is that?
I logged in at the outset as root and din't do an su root.


All times are GMT -5. The time now is 06:19 AM.