Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to linux, so far I can navigate through directories easily and change file permissions, I can also do some python/java stuff within the terminal. My question is that when I am using cd/ls/rm and such, I always use ./ when I am referencing subdirectories. Is this a good or bad habit?

share|improve this question
up vote 2 down vote accepted

./file_name is used to exec a file which is into the current directory. Obviously this file must be executable.

If you want to change into a sub-directory just type

cd sub-directory_name

Which is the same that

cd ./sub-directory_name
share|improve this answer
    
I thought ./ was just to specify the directory you are currently in? like in my home folder I'll do cd ./workspace instead of cd workspace – WillumMaguire Oct 7 '12 at 23:38
1  
Exact! So it is a good habit, I guess. But this ./ is more useful when you wish exec a file, e.g. a bash script – slackmart Oct 7 '12 at 23:41
    
Ok, thank you very much! – WillumMaguire Oct 7 '12 at 23:44
    
Welcome to GNU/Linux world! :- – slackmart Oct 7 '12 at 23:46
2  
using ./file_name is for security purposes. Linux by default does NOT add . to the $PATH so you can't just untarball a package and the person be sneaky and have a nasty binary named ls that you just executed. This forces you to type ./ls if you really do intend on executing this new binary in your current directory (.) instead of the typical ls. – UtahJarhead Oct 8 '12 at 1:38

Once you start using $CDPATH, there is one more distinction between cd subdir and cd ./subdir: the first one searches CDPATH if the directory is not found in the current directory, while the second does not; moreover, the first one ouputs the target path to standard output, while the second does not.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .