What is the ./
that you see on Linux if you do:
$ ls -a
./ ../ other-files
I know ../
represents the parent directory relationship, and I know that we can use ./
to execute files marked as executable, but what is ./
called and why does it show up in ls -a
as a hidden file?
Thanks!
.
Refers to the current working directory.
..
Refers the parent directory of the current working directory.
Directory Structure
Every directory in Unix has a .
and ..
as a reference. To understand it further check the inodes
of .
and ..
with ls -lai
command .
Let say directory a
is the parent directory for directory b
. when you list the contents of directory b
with ls -lai
the inode of .
will point to b
directory and ..
will point to a
directory.
File Listing
.
and ..
can be used for file listing.
$ ls -l ./file1.txt
is same as
$ ls -l file1.txt
In the first case we have used with more specificity.
File execution
When we need to execute scripts that are in current working directory we do it with below methods.
./
means execute script.sh
which is present in the current working directory.
$ ./script.sh
we can pass script.sh
as an argument to bash
and so it is not necessary to specify ./
.
$ bash script.sh
or
$ bash ./script.sh
In case if the current working directory is part of PATH
environment variable, then we can just simply invoke the script without mentioning ./
or bash
$ script.sh
echo ./
will not get expanded because .
is not special to echo
or bash
. Where as the file expansion meta characters like *
, ?
, ..
and others are special.