Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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 –  sgmart Oct 7 '12 at 23:41
    
Ok, thank you very much! –  WillumMaguire Oct 7 '12 at 23:44
    
Welcome to GNU/Linux world! :- –  sgmart 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.