29

For example, I can do the following

touch a

or

touch ./a

Then when I do ls I can view both, so what exactly is the ./ for?

1

3 Answers 3

31

The dot-slash, ./, is a relative path to something in the current directory.

The dot is the current directory and the slash is a path delimiter.

When you give the command touch ./a you say "run the touch utility with the argument ./a", and touch will create (or update the timestamp for) the file a in the current directory.

There is no difference between touch a and touch ./a as both commands will act on the thing called a in the current directory.

In a similar way, touch ../a will act on the a in the directory above the current directory as .. refers to "one directory further up in the hierarchy".

. and .. are two special directory names that are present in every directory on Unix systems.


It's useful to be able to put ./ in front of a filename sometimes, as when you're trying to create or delete, or just work with, a file with a dash as the first character in its filename.

For example,

touch -a file

will not create a file called -a file, and neither would

touch '-a file'

But,

touch ./'-a file'

would.

0
24

The ./ notation is useful when trying to run a script or other executable in the current directory. Unlike the Windows command prompt, Unix (and Unix-like systems like Linux) shells do not check the current directory for executables before checking the PATH environment variable, and Unix systems tend not to include ./ in the PATH for security reasons. By having to specify

./executable

rather than just

executable

the user is saying, "yes, I do want to run this executable in the current directory"

0
6

This is called a relative path.

. represents the current working directory. So if you are currently in /home/jesse, . is simply a link to /home/jesse so when you point to ./ you are really pointing to /home/jesse/

You must log in to answer this question.

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