Linux cd command

In Linux, the “cd” command is used to change the current working directory. It allows you to navigate through the directory structure of your Linux system. Here’s how to use the “cd” command:

  1. Open a Terminal:
    Launch a terminal emulator on your Linux system.
  2. Type the “cd” command:
    Simply type “cd” followed by the directory path you want to change to. For example, to change to the “Documents” directory in your home directory, run:
   cd Documents
  1. Change to a Relative Directory:
    You can also change to a directory relative to your current location. For example, to change to the parent directory (one level up), use:
   cd ..

To change to a subdirectory within the current directory, specify the subdirectory name after “cd”. For example:

   cd subdirectory
  1. Change to the Home Directory:
    To quickly switch to your home directory, you can use the tilde (~) symbol. For example:
   cd ~

This will take you to your home directory, typically located at “/home/username”.

  1. Use Absolute Paths:
    Instead of using relative paths, you can also use absolute paths to change to a specific directory. For example, to change to the “/var/log” directory, run:
   cd /var/log
  1. Use Tab Completion:
    You can take advantage of tab completion by typing the first few characters of a directory name and then pressing the Tab key. It will automatically complete the directory name or display a list of matching options. This can help avoid typing errors and save time.
  2. Print the Current Directory:
    To view the current directory, use the “pwd” command (which stands for “print working directory”). For example:

By convention, if we leave off the argument and just type cd we go HOME:

cd     # go $HOME

Go to the root directory:

cd /	 # go to root

To return to the directory we were last in:

cd -  # cd into the previous directory

   pwd

It will display the full path of the current directory.

<

  1. Exiting the Command:
    The “cd” command doesn’t produce any output unless there is an error. Once you change to the desired directory, you can continue executing other commands or exit the terminal as needed.

The “cd” command is a fundamental tool for navigating the directory structure in Linux. By using different directory paths and options, you can easily move between directories and access the files and subdirectories within them.