Untitled Document
cd Command

cd stands for Change Directory and it is one of the most important and frequently used Linux / Unix command . We often need to move from one directory to other for scripting , checking logs , output files etc. Lets see moe example of cd using Absoulte paths and Relative paths to swicth between directories .

1. Basic example -

Run the cd command on your terminal and it will redirect to your own directory or home directory . So this is one of the way you can go to your home directory , if you are working in some other directories .


2. Moving to your root directory -

Usually the paths are splitted with \ e.g. \I\mangu.the.geek\13.9.14\logs . So the root directory will be the first \ of the path . To go to the root directory run cd command as

   cd \ 

3. Moving to your parent directory , one directory up from current directory

If you want to move one directory up from current directory then run -

   cd .. 

4. want to move two directory up from current directory

If you want to move two or more directories then simply add ../ to above command . We can do this if we want to move to multiple directories up. Just add the ../ up to the level you want to move up.

   cd ../../ 

5. Toggling between two directories

Sometimes we need to move back and forth between two directories , cd command provides toggling option hyphen ( - ) which helps user to toggle between current directory and its previous directory .
   cd -  

6. Example to move in other locations

we can move from one location of a directory to another i.e completely two different location by using relative paths . See the following example - user is now moved from \I\mangu.the.geek\13.9.14\logs to \C\users\lenovo\mngesh\progrs
o/p - \I\mangu.the.geek\13.9.14\logs   
cd \C\users\lenovo\mngesh\progrs

7. Alternative caommand to cd - to reedirest user to its home directory -

In our previous example we have seen that a user can be navigated to its home directory by using cd command withoout any argument .Similary there is special symbol ~ ( tilde) when used with cd will redirect user to its home directory .
cd ~

8. Redirecting an user to another users home directory -

Suppose we want to move to user verma's home directory and you don't know his path , no worries we can go to user Verma's home directory using cd comannd followed by ~ and username , here is the command which will redirect us to Verma's hoem direrctory .
cd ~vermag

9. General Observation -

Sometime user put an extra \ and the end of the pathname to the cd command . Ideally below to example of cd command does the same task . The example is just to give you idea .
cd \C\users\lenovo\mngesh\progrs
cd \C\users\lenovo\mngesh\progrs\
Untitled Document