Blog

03/06/2019

How to change directory in Linux using cd command



I recently made the switch and started using Debian Linux. How do I change directory in Linux using the cd command? How can I change a directory or folder in Linux?

Introduction – You need to use the cd command to move from your present directory to another directory. You must have execute or search permission in the specified directory. This page shows basic examples of how to change directory on Linux using the cd command.

How to change directory in Linux

The procedure changes a directory or folder in Linux as follows:

  1. Let us change to your home directory in Linux, run: cd
  2. If you want to change to the /etc/security/ directory on Linux, execute: cd /etc/security/
  3. Want to go up one level of the directory tree in Linux? Try: cd ..

Let us see some examples and usage in details.

Changes the current directory in Linux

Let us change the current working directory to the home (login) directory in Linux, run:
cd
To print the current working directory, use the pwd command:
pwd
Next change to an arbitrary directory named /etc/ufw/, type:
cd /etc/ufw
pwd

At this stage, you may want to list the directory contents. Hence, try the ls command:
ls
ls -l

Say you need to go down one level of the directory tree (say you want to change to the applications.d), run:
cd applications.d
pwd
ls -l

How do I go back to my home folder or directory in Linux?

Simply type any one of the following command:
cd
OR
cd ~
OR
cd $HOME

Changing to another directory in Linux using the cd command

How to change a folder in Linux

Get list of directories only in the current directory using the following:
ls -d */
Once you know the directory names, change it as per your needs:
cd linux
pwd
ls

To move back to a parent directory directory, type:
cd ..
Verify it:
pwd
ls

Linux change directory using the cd command

Linux change directory and symbolic links

One can force symbolic links to be followed. The syntax is:
cd -L dir1
cd -L link2

To use the physical directory structure without following symbolic links:
cd -P link2

Force symbolic links with the -L option and he physical directory structure with the -P option

Conclusion

This page explained the cd command that allows you to change directories. For more info type the following command at the terminal:
cd --help
OR
help cd

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....
12/08/2019

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...