[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedMay 11, 2023

How to use Cd Command.

This article will show you how to use the cd command to navigate your system’s directory tree.

The cd (“change directory”) command is used to change the current working directory in Linux and other Unix-like operating systems. It is one of the most basic and frequently used commands when working on the Linux terminal.

The current working directory is the directory (folder) in which the user is currently working in. Each time you interact with your command prompt, you are working within a directory.

cd Command

cd is a shell builtin, and its behavior may slightly differ from shell to shell. It uses the shell environment variables to determine necessary information for its execution.

We will cover the Bash-builtin version of cd.

The syntax for the cd command is as follows:

cd [OPTIONS] directory

The command accepts only two options that are rarely used.

  • −L, Follow symbolic links . By default, cd behaves as if the -L option is specified.

  • −P, Don’t follow symbolic links. In other words, when this option is specified, and you try to navigate to a symlink that points to a directory, the cd will change into the directory.

In its simplest form, when used without any argument, cd will take you to your home directory.

When navigating through the file system, you can use the Tab key to autocomplete the names of directories. Adding a slash at the end of the directory name is optional.

To switch to a directory, you must have executable permissions for that directory.

The pwd command allows you to find out what directory you are currently in.

Absolute and Relative Path Names

When specifying a directory to change to, you can use either absolute or relative path names. The absolute or full path starts from the system root /, and the relative path starts from your current directory.

By default, when you log into your Linux system, your current working directory is set to your home directory. Assuming that the Downloads directory exists in your home directory, you can navigate to it by using the relative path to the directory:

cd Downloads

You can also navigate to the same directory by using its absolute path:

cd /home/username/Downloads

In short, if the path starts with a slash (/), it is the absolute path to the directory.

The Parent Directory

On Unix-like operating systems, the current working directory is represented by a single dot (.). Two dots (..), one after the other, represent the parent directory or the directory immediately above the current one.

If you type cd ., you will change into the current directory or, in other words, the command will do nothing.

Suppose you are currently in the /usr/local/share directory. To switch to the /usr/local directory (one level up from the current directory), you would type:

cd ../

To move two levels up to the /usr directory (the parent’s parent), you could run the following:

cd ../../

Here is another example. Let’s say you are in the /usr/local/share directory, and you want to switch to the /usr/local/src. You can do that by typing:

cd ../src

Navigate to the Previous Directory

To change back to the previous working directory, pass the dash (-) character as an argument to the cd command:

cd -

Navigate to the Home Directory

To navigate to your home directory, simply type cd. Another way to return directly to your home directory is to use the tilde (~) character, as shown below:

cd ~

For example, if you want to navigate to the Downloads directory, which is inside your home directory, you would type:

cd ~/Downloads

You can also navigate to another user’s home directory using the following syntax:

cd ~username

Directories with Space in Their Names

If the directory you want to change to has spaces in its name, you should either surround the path with quotes or use the backslash (\) character to escape the space:

cd 'Dir name with space'
cd Dir\ name\ with\ space

Conclusion

By now, you should have a good understanding of what is the current working directory and how to use the cd command to navigate through your system’s directory structure.

Keep reading
How to Add and Delete Users on CentOS 7.
June 12, 2023

How to Add and Delete Users on CentOS 7.

How To Add And Delete Users On CentOS 7. In this tutorial, we will explain how to add and remove users on CentOS 7 systems. How To Add User in CentOS In CentOS, you can create a new user account using the useradd command-line utility. To create a new user account named “username” you…

Read article
How To Secure Nginx with Let’s Encrypt on CentOS 7.
June 8, 2023

How To Secure Nginx with Let’s Encrypt on CentOS 7.

How To Secure Nginx With Let’s Encrypt On CentOS 7. Let’s Encrypt is a new Certificate Authority (CA) that provides a way to obtain and install free TLS/SSL certificates, thereby enabling encrypted HTTPS on web servers. It streamlines the process by providing a software client, Certbot, that…

Read article
How to use ls command.
June 1, 2023

How to use ls command.

How To Use Ls Command. This article will show you how to use the ls command through practical examples and detailed explanations of the most common ls options. ls is one of the basic commands that any Linux user should know. The ls command lists files and directories within the file system, and…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00