Ubuntu: How can I move down one directory



Question:

I know the command for moving up one directory is cd ..

Is there any command to move down one directory?


Solution:1

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.


Solution:2

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


Solution:3

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/.


Solution:4

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.


Solution:5

This doesn't answer exactly the question that was asked, but as was pointed out by someone else, that question didn't really make sense anyway.

But here is the answer to a nearby question. To go back to the directory from whence you came, use cd -

[mike@gwydion Work]$ cd ..  [mike@gwydion ~]$ cd -  /home/mike/Work  [mike@gwydion Work]$   

If you want to save a directory for later reference, do some stuff in between in a bunch of other directories, and then go back, use pushd and popd:

[mike@gwydion Work]$ pushd .  ~/Work ~/Work  [mike@gwydion Work]$ cd ~/Temp/  [mike@gwydion Temp]$ run some command    [mike@gwydion Temp]$ cd ~/SourceCode/  [mike@gwydion SourceCode]$ run some command  [mike@gwydion SourceCode]$ popd  ~/Work  [mike@gwydion Work]$ popd  bash: popd: directory stack empty  [mike@gwydion Work]$   

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »