19

Based on the question: How to make using command prompt less painful, what are the . and .. entries in the most voted answer? I see it when I do a dir command but it isn't visible to the user in the form of a file.

In case you dont know what I mean here's an example:

.
..
Su.exe
Sup.txt
SuperUser.COM

4 Answers 4

45

The . is the current directory, while .. signifies the parent directory. It makes things quicker at the command line as well so you don't need to type out full paths.

example:

go up 2 directories:

cd ..\..\

or on a UNIX based system, to run executable binaries in the current directory:

./program

A lot of UNIX scripts will also utilize . to represent the current directory, in order to scan for files for example (Perl):

#!/usr/bin/perl

opendir ( DIR, "." ) || die "Error opening current directory\n";
while( ($f = readdir(DIR))){
     print("$f\n");
}
closedir(DIR);

It is much more portable if you wish to move the script around to different directories or systems since a directory name is not hard-coded.

8
  • 3
    It's little known, but the Windows command line extends this further. . = this directory .. = parent directory ... = parent's parent directory 3 dots is sometimes useful, much more than that and it's just too hard to deal with. Sep 9, 2009 at 3:57
  • 6
    3 dots does not work for me, using Vista Sep 13, 2009 at 0:21
  • 2
    nor me on Windows 7 64 bit RTM. Sounds like a myth to me. what's wrong with ..\.. anyway?
    – AdamV
    May 26, 2010 at 14:45
  • 3
    @salmonmoose: Doesn't work for me on XP either. May 26, 2010 at 14:59
  • 2
10

The .. is used to navigate up the hierarchy of the file system. It's useful when you don't want to type a long path, or when writing a script/program that doesn't know where exactly it will be installed but it knows that ../media/ should hold all the images/videos/icons etc.

The single dot . is useful in linux where you want to run an executable in the current directory so you type ./a.out because the command shell by default doesn't search the current directory for executable files (for security reasons).

The single dot . is also used if you want to pass the current directory as an argument to a command.

5
  • 1
    PowerShell also doesn't include . in the path list for searching executables.
    – Joey
    Sep 8, 2009 at 5:16
  • How to pass '.' as an argument to a command?
    – AbstProcDo
    Nov 10, 2017 at 5:51
  • @DeFu you pass the dot as a dot, for example: ls .
    – hasen
    Nov 10, 2017 at 6:15
  • ls functions same as ls .
    – AbstProcDo
    Nov 10, 2017 at 6:31
  • @DeFu well yes but when you do ls . you are passing '.' as an argument to 'ls'; isn't that what you asked? It functions the same because by default ls lists the current directory, and . is the current directory. But you are passing it to the command, for sure.
    – hasen
    Nov 10, 2017 at 9:20
5

The . is the current directory. You rarely need to use this; most commands will assume the current directory. The .. is the next level up; this is a rather useful shortcut. If you are in C:\foo\bar and you want to go to C:\foo\bar2 you can say

cd ..\bar2

and you will be in C:\foo\bar2. If you don't want to go to bar2 but only want to run C:\foo\bar.exe, then you can say

..\bar.exe

or ..\bar to run it without going back up to the parent directory. Of course, this is more useful when you are it represents a longer path that C:\foo (such as "C:\Users\Daniel\My Dropbox\".

1
  • 1
    I find . to be quite useful at times, especially when copying or moving files to the current location (copy F:\*.foo .) or referring to it otherwise (start . opens the Explorer in the current directory, for example).
    – Joey
    Sep 8, 2009 at 5:17
3

They stand for:

.

The current dir

.. 

Represents the parent dir

So if you have the executable "su.exe" in:

  • Your Path environment variable ( let say C:\MyExecutables\su.exe )
  • Your current dir
  • Your parent dir.

You could execute each one like this:

 su.exe  

Executes the one in the Path

.\su.exe 

Executes the one in the current dir

..\su.exe

Executes the one in the parent dir.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy