cd command with examples in Linux / Unix

cd command with examples in Linux / Unix

cd command is used to change directory in Linux / Unix environment. The abbreviation of “cd” is “Change Directory”. It is the most basic and important command in linux / Unix command prompt environment. OK lets see some example about cd command.

cd command with examples in Linux / Unix

How to go to your home directory with cd command

#cd
#pwd

Use pwd(present working directory) command to  to verify that you are in your home directory.

Another Method

#cd ~
#pwd

Use pwd(present working directory) command to verify that you are in your home directory.

How to go to your previously working directory

#cd –

The “cd -” command will fetch the input directory from “echo $OLDPWD” variable and use it if you give “cd -”

How to use relative and absolute path with cd command

I will give you some basic tips about relative and absolute path. we will see deep about it in a separate blog later. Relative path always starts with “/” and absolute path always starts with “..” symbol. Relative path should be a full path but absolute path can start from any where in between.

Consider that you are in your home directory right now. If you want to go to http configuration files location “/etc/httpd/conf” use absolute path

#cd /etc/httpd/conf
#pwd

If you want to go to “/etc” two steps backward use relative path righ from there

#cd ../../
#pwd

cd command with examples in Linux / Unix

That’s it you have successfully switch over in to folder “/etc”

Cd command with wild card example

Suppose consider that you want to go to folder “/etc/samba” folder so i am going to use cd command with wild card. Press “Tab” after giving below command for auto complete.

#cd /et*/sam*

The below command will take you to /etc/httpd/conf/ folder. Press “Tab” after giving below command for auto complete.

#cd /etc/htt*/co*f




Leave a Reply

Your email address will not be published. Required fields are marked *