Change Directory (cd) Examples | Unix and Linux Command

  • Updated
  • Posted in Programming
  • 3 mins read


The Change listing (cd) command is without doubt one of the easy instructions in Unix (or Linux) and it is extremely simple to make use of. The cd command is used to vary from the present listing to a different listing. The syntax of cd command is

cd [directory]
Here listing is the identify of the listing the place you want to go.

CD Command Examples

1. Write a unix/linux cd command to vary to residence listing?

Just merely sort cd command on the unix terminal and then press the enter key. This will change your listing to residence listing.

> pwd
/usr/native/bin

Now i’m within the /usr/native/bin listing. After typing the cd command and unix window, you’ll go to your house listing.

> cd
> pwd
/residence/matt

Here pwd command shows the current working listing.

2. Write a unix/linux cd command to return to 1 listing?

The cd .. adjustments the listing to its dad or mum listing by going again one degree. The house between the cd and .. is should.

> pwd
/var/tmp
> cd ..
> pwd
/var

3. Write a unix/linux cd command to return to 2 directories?

The cd ../../ takes you again to 2 directories. You can prolong this cd command to return to n variety of directories.

> pwd
/usr/native/bin
> cd ../../
> pwd
/usr

4. Write a unix/linux cd command to vary the listing utilizing absolutely the path?

In case of adjusting listing utilizing absolute path it’s a must to specify the total listing path. Absolute path directories at all times begin with a slash (/). An instance is altering your listing to /usr/bin from your house listing.

> cd /usr/bin

5. Write a unix/linux cd command to vary the listing utilizing the relative path?

In relative path, it’s a must to specify the listing path relative to your present listing. For instance, you might be in /var/tmp listing and you wish to go to /var/lib listing, then you should use the relative path.

> pwd
/var/tmp
> cd ../lib
> pwd
/var/lib

Here the cd ../lib, first takes you to the dad or mum listing which is /var and then adjustments the listing to the lib.

6. Write a unix/linux cd command to vary again to earlier listing.

As an instance, i’m within the listing /residence/matt/paperwork and i modified to a brand new listing /residence/matt/backup. Now i wish to return to my earlier listing /residence/matt/paperwork. In this case, you should use the cd – command to return to the earlier listing.

> pwd
/residence/matt/paperwork
> cd /residence/matt/backup
>pwd
/residence/matt/backup
> cd -
> pwd
/residence/matt/paperwork

Leave a Reply