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?
command linefilenamesfileslinux
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?
Best Answer
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 thetouch
utility with the argument./a
", andtouch
will create (or update the timestamp for) the filea
in the current directory.There is no difference between
touch a
andtouch ./a
as both commands will act on the thing calleda
in the current directory.In a similar way,
touch ../a
will act on thea
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,
will not create a file called
-a file
, and neither wouldBut,
would.