Change Directory (Navigate or Go to specific directory) in linux computer system can be performed via terminal using a simple command line interface. While directory or folder also can be created, modified, deleted, renamed, grown, and shrunk (truncated). In most cases, software programs that are executed on the computer handle these operations, but the user of a computer can also modify directories if necessary.

For instance, directories are normally can be changed by program in response to user commands, but the user can also change these directories directly by using a file manager program such as Windows Explorer (on Windows computers) or via shell or terminal emulator with command (CLI) on linux system.

How To Change Directory in Linux?

You can easily change (or go to specific) directory in linux via terminal on your system using the command line with the following methods cd, and Information.

Linux Command To Change Directory

“cd” command is used to changes your current working directory. In other words, it moves you to a new directory or folder in the file system. This is one of the most common administrative tasks you can perform when working on terminal with the linux command line.

To change (or go to specific) directory in linux:

  1. Open “Terminal” on your linux system.
  2. Use “cd” command with option as alternative and specify the “directory-name” or path where you want to go to.
  3. The syntax for using the “cd” command as shown below.
    cd [option] [directory-name or path]
    • Example change a working directory in the current directory.
      cd Documents

      This will move or navigate you to “Documents” as new current working directory.

    • Example change a directory with relative path of directory name.
      cd /home/user/Documents

      If the path starts with a slash “/” it is the absolute path to the directory.

    • Example change a “directory name” with space.
      cd 'My Documents'
      cd My\ Documents\

      Surround the path with quotes or use the backslash (\).

    • Example navigate directory one level up.
      cd ../

      Suppose you are currently in the “/user/Documents/local”, it’ll switch to the “/user/Documents” directory

    • Example navigate directory two level up.
      cd ../../
    • Example navigate to previous directory.
      cd -
    • Example navigate to home directory.
      cd ~
    • Example change a directory in simple relative path.
      cd ~/Documents

      Assuming “Documents” is inside your home directory.

  4. Done, now you’ve already changed the directory.

More Information

“cd” command related information can be obtained with “–help”.

cd --help

cd: cd [-L|[-P [-e]] [-@]] [dir]
Change the shell working directory.

Change the current directory to DIR. The default DIR is the value of the HOME shell variable.

The variable CDPATH defines the search path for the directory containing DIR. Alternative directory names in CDPATH are separated by a colon (:). A null directory name is the same as the current directory. If DIR begins with a slash (/), then CDPATH is not used.

If the directory is not found, and the shell option `cdable_vars’ is set, the word is assumed to be a variable name. If that variable has a value, its value is used for DIR.

Options:

  1. -L force symbolic links to be followed: resolve symbolic links in DIR after processing instances of `..’
  2. -P use the physical directory structure without following symbolic links: resolve symbolic links in DIR before processing instances of `..’
  3. -e if the -P option is supplied, and the current working directory cannot be determined successfully, exit with a non-zero status
  4. -@ on systems that support it, present a file with extended attributes as a directory containing the file attributes

The default is to follow symbolic links, as if `-L’ were specified.

`..’ is processed by removing the immediately previous pathname component back to a slash or the beginning of DIR.

Exit Status: Returns 0 if the directory is changed, and if $PWD is set successfully when -P is used; non-zero otherwise.

In general, a directory can contain either a list of files or a list of links to files. Within this definition, it is of paramount importance that the term “file” includes “directories”. This permits the existence of directory hierarchies, i.e., directories containing sub-directories.

License: CC-BY-SA Creative Commons License
☝️