Mkdir

hi linux expert
what is a difference between:
mkdir test and mkdir ./test

and also
if ( -e /test ) then and if ( -e ./test ) then

thanks in advance

Hi,

Taking them in turn:

mkdir test and mkdir ./test

In practical terms, there isn't likely to be much difference between them, and they are generally going to be interchangebale in use. The key to understanding what they do though (and why they both do the same thing) is understanding the meaning of './' specifically.

In UNIX-style nomenclature, the '.' character represents your current directory. The '/' symbol is the path separator, and is used to separate one directory in a path from another. All absolute paths starting at the root of the filesystem tree begin with '/'.

So, in the first instance, mkdir test simpy creates a directory called 'test' in your current working directory, without specifying a path. In effect, this works out to be identical to specificying the current working directory in your path by doing mkdir ./test .

In both cases, you're going to end up with a sub-directory of your current working directory (that is, the directory you are in when you run the 'mkdir' command) called 'test'. Most commands (mkdir amongst them) are generally going to assume if you don't specify a path you must be referring to your current directory, which is why in this one single instance you can use both these forms interchangeably.

Moving on to your second question:

if ( -e /test ) then and if ( -e ./test ) then

Here there's a big difference in meaning, and these two tests will do entirely different things. The path '/test' refers to a file or directory beneath the root of the filesystem (that is, the very top of the filesystem tree) called 'test'. Whereas './test' refers to a file or directory beneath your current working directory called 'test'.

So unless you happen to have / as your current working directory, the meaning of these will be very different. '/test' will always refer to something called 'test' underneath the root directory, no matter where you happen to be yourself in the file system tree at the time. Whereas './test' will always refer to something called 'test' underneath whatever directory you happen to be in at the time.

Hope this helps.