How can I move down one directory
The main difference between moving up a directory, and moving down a directory, in the directory tree is:
-
Moving up - there is only one option, hence the command doesn't need to mention the folder name:
cd ..
-
Moving down - there might be several sub-directories, hence you first need to choose sub-directory, to change directory down into example-dir the command is:
cd example-dir
In older versions of bash (e.g: 4.3) you could do cd *
and it would go to the first sub directory it found:
$ ls
dir1/ dir2/ dir3/
$ cd *
Now we are in dir1/
.
The way by which you want to go down by one directory is not possible because there is only one parent directory which is denoted by ..
, but there can be multiple directories inside a directory and thus you have to mention the one you mean. You have to use cd example
to move down by one onto the directory example
.
But there is a shortcut: use Tab completion for this. To move down by one into the example
directory, you could enter cd e
and press Tab and if example
is the only directory beginning with e
the shell will automatically complete the command to cd example
. If there are others beginning with e
, double Tab will list matches, and you can type ex
or whatever is needed and press Tab again and so on.
You can move up cause because there is one directory but when we talk about going down there can be more than one that is why we have ls
we will list all the available directory and then we change directory one down in which we needed to go by the command cd examle1
.
$ ls
dir1 dir2 sir3
$ cd dir1
$ cd ..
$ cd dir2
And so on.