Ugacomp

How to change directory locations in Linux using the terminal

Where necessary, you may need to have access to a VPS server so you can follow how to implement the steps in this article.  You can get a cheaper VPS Server from Contabo with 4vCPU cores, 8GM RAM, and 32TB Bandwidth for less than $5.50 per month. Get this deal here now

Table of Contents

Cloud VPS S

$5.50 Monthly
  • 4 vCPU Cores | 8GB RAM

CLOUD VPS M

$15.50 Monthly
  • 6 vCPU Cores | 16GB RAM

CLOUD VPS L

$17.50 Monthly
  • 8 vCPU Cores | 24GB RAM

In the Linux command line, navigating through the file system is a fundamental skill. Changing directory locations is a common operation, and understanding how to do it efficiently can significantly enhance your command-line proficiency. This article will guide you through the process of changing directory locations in Linux using various command examples.

Using the cd Command

The primary command for changing directories in Linux is cd, which stands for “change directory.” Here’s a basic example:

cd /path/to/directory

Replace “/path/to/directory” with the actual path of the directory you want to navigate to. If the path contains spaces, enclose it in quotes.

cd "/path/with spaces/"

Moving Up One Directory Level

To move up one directory level, you can use the following command:

cd ..

This command takes you back to the parent directory of your current location.

Going Home

The tilde (~) character is a shortcut for your home directory. Use it to quickly return to your home directory:

cd ~

Absolute and Relative Paths

An absolute path starts from the root directory:

cd /absolute/path/to/directory

A relative path is based on your current location.

cd relative/path/from/current/location

Tab Completion

Tab completion is a time-saving feature in Linux. You can type the initial characters of a directory or file name and press the “Tab” key to auto-complete. If multiple options exist, press “Tab” twice to see a list.

cd /pat[TAB]

Using Variables

You can use environment variables to make your commands more flexible. For example, to switch to the user’s home directory:

cd $HOME

Creating Directory Structures

The mkdir command is used to create directories. You can combine it with the cd command to quickly navigate into the newly created directory:

mkdir new_directory && cd new_directory

This command creates a new directory named “new_directory” and then changes your current working directory to that location in one go.

Navigating to the Previous Directory

The hyphen (-) is a shortcut for the previous directory you were in. This is particularly useful for toggling between two directories:

cd -

Using this command will switch your current directory to the last one you were in.

Exploring Directory Contents

The ls command lists the contents of the current directory. Combine it with cd to navigate into a specific directory displayed by ls:

ls
cd directory_name

Using Wildcards for Quick Navigation

Wildcards like the asterisk (*) can be used to match multiple directories or files. For instance, to navigate into a directory that starts with “example”:

cd example*

This will match the first directory that starts with “example.”

Hire us to handle what you want

Hire us through our Fiverr Profile and leave all the complicated & technical stuff to us. Here are some of the things we can do for you:

  • Website migration, troubleshooting, and maintenance.
  • Server & application deployment, scaling, troubleshooting, and maintenance
  • Deployment of Kubernetes, Docker, Cloudron, Ant Media, Apache, Nginx,  OpenVPN, cPanel, WHMCS, WordPress, and more
  • Everything you need on AWS, IBM Cloud, GCP, Azure, Oracle Cloud, Alibaba Cloud, Linode, Contabo, DigitalOcean, Ionos, Vultr, GoDaddy, HostGator, Namecheap, DreamHost, and more.
 

We will design, configure, deploy, or troubleshoot anything you want. Starting from $10, we will get your job done in the shortest time possible. Your payment is safe with Fiverr as we will only be paid once your project is completed.