What is the command to change the current directory?

OpenWindows Advanced User's Guide

The cd (change directory) command allows you to move around within the file system hierarchy:

$ cd /usr/lib $ pwd /usr/lib

When you type the cd command by itself, you return to your home directory. For example, if your home directory was /home/user1:

In the C shell, the tilde (~) is used as a shortcut for specifying your home directory. For example, you would type the following to change to the subdirectory music within your home directory:

You can also use this shortcut to specify another user's home directory. For example:

where username is another user's login name, would change to that user's home directory.

Note -

If you are using the Bourne shell, the ~ shortcut will not work.

If you are using the Bourne shell, it may be possible that your system administrator has configured the system so that you can type $home to specify your home directory. If this is the case, then typing:

changes you to the subdirectory music in your home directory. Likewise, typing:

changes you to the specified user's home directory, where username represents another user's login name.

The directory immediately "above" a subdirectory is called the parent directory. In the preceding example, /home is the parent directory of /home/user1. The symbol .. ("dot-dot") represents the parent directory. Therefore, the command cd .. changes the working directory to the parent directory, as in this example:

$ pwd /home/user1 $ cd .. $ pwd /home

Suppose your current working directory is /home/user1 and you want to work with some files in /home/user2. Here is a useful shortcut:

$ pwd /home/user1 $ cd ../user2 $ pwd /home/user2

../user2 tells the system to look in the parent directory for user2. As you can see, this is much easier than typing the entire path name /home/user2.

  • © 2010, Oracle Corporation and/or its affiliates

The Command prompt, sometimes also referred to as cmd.exe in short, is a command line interpreter in Windows operating system, and has been in use since the earliest days of Microsoft operating systems, dating back to the DOS days.

Offered as an alternative to Windows GUI, the command prompt offers far more control and functionalities to the average Windows user, than the normal GUI ever can.

But, before you can perform any wizardry with the Command prompt, you’ll first have to learn how to change directories in it. In this article, we’ve covered some of the easiest methods to change your Command prompt directory in Windows 10/11.

Let’s jump right in.

3 ways to change the Command prompt directory

There are a plethora of ways to change the Command prompt directory on Windows 10/11. First, we’ll begin with what is most probably the most straightforward of them all: the cd command. Let’s go.

Change your Command prompt directory with cd command

The cd command, short for Change Directory, lets you jump from one directory (folder) to another without any hassles.

Simply type in ‘cd’ in the Command prompt and hit Enter. From there, you’ll be taken to the top of your Command prompt directory instantly. As you will see on your Command prompt screen, you’ll be taken to the root directory in Windows “C:” drive.

To move in to a particular directory, just enter cd followed by the directory name . For instance, we moved in to the Downloads directory located inside the root directory of our Windows 10 here.

For multiple word directories, you may have to enclose the name in quotes, for example cd "onenote notebooks" - one tip here, you can start typing a directory name, and then hit the tab key, and Windows will fill in the name for you. If you have multiple directories with similar names (say files 1, files 2, files 3, etc) keep hitting the tab key and Windows will cycle through the possible matches.

Alternatively, instead of going straight to the root directory, you can also go back to the previous folder by adding ..  after cd command. So, go into your Command prompt, type in cd .., and hit Enter, as we've done in our Windows 11.

Changing the drive in Command prompt

If, in contrast, you want to change your directory altogether, then you’ll have to type the drive name, followed by :. So, if you’re in the “C:” drive right now, and you'd like to move in to your “D:” drive, just type in “D:” in the Command prompt and hit the Enter.

Another thing to keep in mind is that the Command prompt is case-insensitive, meaning that it treats capital and small case letters as the same. So, it doesn’t matter if you type “D:” or “d:”—the Command prompt will interpret both of them as the same.

Another command that deserves a special mention is the dir command. Type in the dir in the Command prompt and you’ll see a list of files and folders inside the parent directory.

Now, if you want to go inside a specific directory from here, just use the cd command from above, along with the name of the directory, as we did above.

Change directories in CMD by dragging the folder

You can also use the GUI along with the Command prompt here. Type in cd in the Command prompt, drag the folder that you want to move in into the Terminal, and hit Enter.

The Command prompt will directly switch to the desired folder.

Changing directories in  CMD (Command prompt)

If becoming a Terminal pro is what you're after, then being able to change your terminal directories is just one of many hacks you’ll be mastering along the way. Make no mistake, as this is only the beginning, and you’ll be learning a lot more when you dive into the Command prompt more deeply.

Share This Post:

Postingan terbaru

LIHAT SEMUA