Here are more examples of using the cd command:
-
Change to a Subdirectory:
If you are in/home/userand want to go todocuments:cd documents -
Change to a Nested Subdirectory:
If you want to go directly toprojectsinsidedocuments:cd documents/projects -
Change to a Directory with Spaces:
If the directory name has spaces, use quotes:cd "My Documents"or escape the space with a backslash:
cd My\ Documents -
Change to a Directory Using an Absolute Path:
To change to a directory using its full path:cd /home/user/documents/projects -
Change to the Root Directory:
To go to the root of the file system:cd / -
Change to a Directory with a Shortcut:
If you have a directory nameddownloadsin your home directory:cd ~/downloads -
Change to a Directory Using Environment Variables:
If you have an environment variable set for a directory:cd $MY_DIR -
Change to the Last Directory Visited:
To switch back to the last directory you were in:cd -
These examples illustrate various ways to use the cd command for navigating directories in the terminal.
