cd - change directory command in linux
syntax
cd [path to directory]
// type "cd <path to directory>" and press enter
user@host:~ cd mydir/
user@host:~/mydir
The "cd" command is to change the current directory to the given directory, either sub directory or to the directory given in path.
to change the current directory to sub directory, relative path is enough as below
user@host:~/mydir cd ./subdir/
user@host:~/mydir/subdir
examples
change directory to given path
user@host:~ cd /home/user/myotherdir/
change directory to home directory
// dont give path, just type "cd" and enter in terminal
user@host:~/mydir/subdir cd
user@host:~
change directory to previous directory
// dont give path, just type "cd -" and enter in terminal
user@host:~ cd -
user@host:~/mydir/subdir
change directory to tmp directory
// type "cd /tmp" and enter in terminal
user@host:~/mydir/subdir cd /tmp
user@host:/tmp
change directory to previous directory from tmp directory
// dont give path, just type "cd -" and enter in terminal
user@host:~ cd -
user@host:~/mydir/subdir
change current directory to another directory in parent directory using relative path
//parent directory is having 2 directories, changing from subdir to subdir2
user@host:~/mydir/subdir cd ../subdir2
user@host:~/mydir/subdir2