Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Linux

How to Change Directory in Linux Using cd Command

by Hollie Moore
4 months ago
in Linux
Change Directory In Linux Using Cd Command
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

Discover how to change directories in Linux using the powerful cd command. Master absolute and relative paths, and navigate the file system effortlessly. Boost your command line skills now!

ADVERTISEMENT

The cd command is a crucial tool for accessing the file system by altering the current working directory when using the Linux command line interface. You can navigate between directories and access files and directories on your Linux system by learning how to use the cd command. We’ll go through how to use the cd command correctly in this post and examine all of its features.

Table of Contents

  1. Prerequisites
  2. How to Use the Linux cd Command
  3. Fundamental Syntax
  4. Absolute and Relative Path Names
  5. Go to the Parent Directory
  6. To Change the Previous Working Directory
  7. Switch to the Home Directory
  8. Navigate to the Root Folder
  9. Make the switch to a directory name with spaces
  10. Changing Directory and List Content
  11. Autocomplete Directory Name

Prerequisites

  • A system running a Linux distribution.
  • You should have a non-root user on an Ubuntu 22.04 server with Sudo permissions in order to finish this tutorial.
  • Access to the terminal window or command line
  • Read our basic server setup guide to find out how to accomplish this configuration.

How to Use the Linux cd Command

Change Directory is the meaning of the cd command using terminal. Cd, one of Linux’s most basic commands, is now used everywhere to change folders. There are also several other command implementations available, like chdir for MS-DOS platforms.

Fundamental Syntax

The basic syntax for the cd command is:

ADVERTISEMENT
cd [options] [path]

In the command above:

You might also like

Symbolic Links In Linux

Symbolic Links in Linux: What They Are and How to Use Them

2 months ago
Ubuntu Password

Reset your Forgotten Ubuntu Password in 2 Minutes

2 months ago
  • Uses the cd command when entered.
  • [options]: Including options modifies how the command operates.
  • [directory]: The directory’s path where you want to move to.

In its most basic form, cd will transport you to your home directory when invoked without any arguments.

You can use the Tab key to have the names of directories autocomplete while traversing the file system. It is not required to conclude the directory name with a slash. You need to have executable permissions on a directory in order to switch to it.

ADVERTISEMENT

To display the full path of your current directory, enter the following command:

pwd

Absolute and Relative Path Names

Both absolute and relative path names can be used to identify a directory to change to. The full or absolute path begins at the system root /, while the relative path begins in the current directory.

ADVERTISEMENT

Your home directory is the default setting for your current working directory when you log into a Linux system. If the Downloads directory is present in your home directory, you can access it by using the relative directory path:

cd Downloads

Using its absolute path, you can access the same directory as well:

ADVERTISEMENT
cd /home/username/Downloads

Simply put, the absolute path to the directory is one that begins with a slash (/).To easily go to different directories without having to write the entire pathname, Cd keeps track of which directories are above and below the current directory.

Use the ls command to list down every directory in that folder if you are confused of the exact name of the subdirectory you wish to go to.

ADVERTISEMENT

Go to the Parent Directory

A directory that has one or more subdirectories is referred to as the parent directory. In other words, if you’re /home directory contains the directories /Desktop and /Downloads, then that directory will serve as the parent directory for those two folders.

The letters .. and. stand for the parent directory and the current directory, respectively.

Switch to the parent directory by using the double-dot character (..).

cd ..

You can go up the directory tree one level with the aforementioned command. You can advance up the directory tree by passing more. characters.

Moving two levels up from your current working directory:

cd ../../

A specific directory can also be supplied that is one level above the the working directory at present.

cd ../../

To Change the Previous Working Directory

The – (hyphen) character makes it simple to return to the previous working directory while working with many directories at once.

If your current working directory is /home and you change to /root, as an illustration. Then the working directory will change to /root, and the working directory before that was /home.

You can return to the previous directory, /home, by typing the following command.

cd -

Additionally, using the cd command and then a space will return the user to their previous working directory.

cd 

Switch to the Home Directory

The /home directory is a particular location on a Linux system designated for a user’s private documents, applications, and subfolders. The home directory is automatically configured as the current working directory when you log in to your system.

The ~ (tilde) character has been designated as a special character for the home directory.With the cd command, you can simply pass the ~ character to change the current working directory to /home rather than entering the full path to your home directory (/home/username).

cd ~

You can follow these steps to navigate to another user’s home directory.

cd ~username

We changed the current working directory to /Desktop in the previous section. You can reduce the size of the command to half by using the character to indicate the /home directory.

cd ~/Desktop

Navigate to the Root Folder

The / character in a Linux-based operating system stands for the /root directory, just like the home directory. The root folder can be reached at any time by:

cd /

Make the switch to a directory name with spaces

Your computer’s folder names won’t all be single words. The character “space” may be present in some of them. as in /home/username/Important Documents.

The directory name will not be specified in such cases, and an error will be returned.

cd /Important Documents
output
bash: cd: too many arguments

Use quotes around the pathname to change to directories that have spaces in their names. Please take note that the command supports both single and double quotes.

cd 'Important Documents'
cd "Important Documents"


As an alternative, you can remove spaces by using the backslash () character.

cd Important\ Documents

Changing Directory and List Content

To switch to a new directory and list its contents at the same time, add the ls command to the cd command using the && flag.

cd [path to directory] && ls

Using the above example:

cd Example_Directory && ls

Autocomplete Directory Name

The Linux terminal doesn’t have autocomplete by default. You can install and configure bash-completion package and use the autocomplete feature. If you don’t know the name of the directory you’re trying to move to you can press press the Tab key on your computer following the command.

cd X[Tab]

Conclusion 

After reading this guide, you ought to be able to use the Linux cd command to navigate around and alter the current working directory in the terminal window. Please feel free to share your thoughts and feedback in the comment section below.

Tags: CentOSDebianUbuntu
Share4Tweet2SendShare
Hollie Moore

Hollie Moore

Greetings, I am a technical writer who specializes in conveying complex topics in simple and engaging ways. I have a degree in computer science and journalism, and I have experience writing about software, data, and design. My content includes blog posts, tutorials, and documentation pages, which I always strive to make clear, concise, and useful for the reader. I am constantly learning new things and sharing my insights with others.

Comments 1

  1. Avatar Of Arthur Pedant Arthur Pedant says:
    3 months ago

    “The Linux terminal has an autocomplete feature”

    No it does not.

    The autcomplete feature is a feature of whichever shell which you are using (most probably but not necessarily bash). cd is a built in command of the Bourne Again Shell (bash), as well as other shells (tcsh, zsh etc).

    And is there no love for the change directory related commands pushd and popd?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

&Quot; Systemd Service On Linux

How to Create a New systemd Service on Linux: A Step-by-Step Guide

3 months ago
List Groups In Linux

How to List Groups in Linux: A Guide for Beginners

3 months ago
Hostname In Linux

How to Modify the Hostname in Linux

3 months ago
Linux Systems

Linux systems Hacked with OpenSSH Malware

3 months ago

Follow Us

Trending Articles

Google Bard Extension

Google Bard Extensions: How to Link Your Gmail, Docs, Maps, and More to an AI Chatbot

September 21, 2023

Create High Quality AI Cover Song with Covers AI

5 Best Fantasy Minecraft Servers in 2023

Microsoft Unveils New Disc-Less Xbox Series X with Lift-to-Wake Controller

5 Best Laptop for Minecraft in 2023: Top Picks for All Budgets

AI Statistics and Trends: What You Need to Know in 2023

Popular Articles

Ai Youtube Video Summarizers

9 Best AI YouTube Video Summarizers Online

August 24, 2023

7 Best AI Face Generator: Create Realistic Faces from Text Online Free

Jenni AI: How to Use AI Writing Assistant for Amazing Content

10 Best AI Video Generator Free of 2023

Microsoft Editor vs Grammarly: Which is the Best Grammar Checker?

5 Free Watermark Maker: Create Transparent Watermarks for Images Online

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.