How To Change Listing in Linux Utilizing the cd Command

System navigation is one of the most basic tasks a user can perform on an operating system. While there are many file managers available that allow you to switch directories and graphically navigate your hard drives, you can get better control of your system by doing the same from the command line.

Fortunately, Linux provides you with a command called cd that you can use to easily change the current working directory on your terminal.

Here's how you can use the cd command on Linux, the only utility you'll ever need to browse directories on your system storage.

Using the cd command on Linux

The cd command stands for Change direction. CD is one of the most basic commands in Linux and a global command for changing directories. Some other implementations of the command like chdirthat are used in MS-DOS systems are also provided.

Basic syntax

The basic syntax of the cd command is:

CD (options) (path)

…Where Options are the arguments passed with the command and path is the absolute or relative path to the directory.

Absolute and relative path names

Before you can fully use the cd command, you must understand the difference between absolute and relative pathnames. The absolute path name is the full path to the directory, starting with the / (Root) Folder.

On the other hand, the relative path name is derived from the current working directory. You can efficiently move the directory tree up and down using the cd command if you are familiar with relative paths.

For example if your current working directory is /At homeand you want to change the directory to / Desktop. Then with the absolute path name:

cd / home / username / desktop

On the other hand, if you want to switch / Desktop Directory that uses a relative path, all you need to do is enter:

CD / desktop

Cd keeps track of which directories are above and below the current directory so a user can quickly switch to other directories without typing the full path name.

If you don't know the exact name of the subfolder you want to go to, use the ls command to list each directory in that folder.

Go to the home directory

On a Linux system, the /At home Directory is a special directory reserved for a user's personal files, programs, and subfolders. When you log into your system, the home directory is set as the current working directory by default.

A special character is assigned to the home directory – the ~ (Tilde) Character. Instead of specifying the full path to your home directory (/ home / username) you can just pass that ~ Characters with the cd command to change the current working directory to /At home.

cd ~

You can also navigate to another user's home directory as follows.

cd ~ username

Related: How to List All Users on Linux

In the previous section we changed the current working directory to / Desktop. You can use them in the command ~ Characters for designating the /At home Directory and remove the command to half its size.

cd ~ / desktop

Just like the home directory, the /. Character denotes the /Root Directory on a Linux-based operating system. To switch to the root folder at any time:

cd /

Change to the previous working directory

If you are working with several directories at the same time, you can easily switch to the previous working directory with – (hyphen) Character.

For example if the current working directory is /At home and you switch to /Root Directory. Then, /Root becomes the current working directory, and /At home will be the previous working directory.

Typing the following command will take you to the previous directory i.e. H. /At home.

cd –

Also issue the cd command followed by a place The character takes the user to the previous working directory.

CD

Change to the parent directory

The directory, which consists of one or more subdirectories, is called the parent directory. Simply put, if you have / Desktop and / Downloads Folder in your /At home Directory, then the /At home Directory is the parent directory for / Desktop and / Downloads.

The .. and . Characters stand for the parent directory or the current directory.

Use the double points Character (..) to switch to the parent directory.

cd ..

The above command takes you one level up in the directory tree. You can also pass additional ones .. Character to move the directory tree further up.

To move two levels above your current working directory:

cd ../../

You can also pass a specific directory one level above the current working directory.

cd ../Folder

Change to a directory name with spaces

Not every folder on your system has a one-word name. Some of them might contain that place Character. For example, / home / username / Important documents.

In such situations, specifying the directory name will return an error.

CD / important documents

Output:

bash: cd: too many arguments

To switch to directories with spaces in the name, include the path name Quotes as follows. Note that you can use both single and double quotation marks in the command.

cd & # 39; Important Documents & # 39;
cd "Important Documents"

Alternatively, you can use that Slash () Character to escape the rooms.

cd Important Documents

Related topics: Getting started with Linux

System navigation from the command line

The Linux Terminal is a powerful text interface for controlling how your computer works. You can perform almost any task from the command line. Change directories, remotely copy files and folders, list file information, edit configuration files, whatever you call it. There is one command for anything you want to do on Linux.

There is a downside to having so many commands, however. Not everyone can learn and memorize the commands, let alone the amount that is available in the first place. However, if you are a novice Linux user, you will not use all of the utilities available on your system.

Instead, learning a few basic commands to help you perform basic operations is more than enough to get you started with the operating system.

9 Basic Commands for Getting Started with Linux

Would you like to familiarize yourself with Linux? Start with these basic Linux commands to learn standard computing tasks.

Continue reading

About the author

Deepesh Sharma
(38 articles published)

Deepesh is the junior editor for Linux at MUO. He has been writing informational content on the Internet for over 3 years. In his spare time he enjoys writing, listening to music and playing the guitar.

More
From Deepesh Sharma

Subscribe to our newsletter

Sign up for our newsletter to receive tech tips, reviews, free e-books, and exclusive offers!

One more step …!

Please confirm your email address in the email we just sent you.

Leave a Reply

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