Moving Into and Out of Directories with the "cd" Command (2024)

Moving into and out of Directories

In this video, we'll use the "cd" command to move into another directory before we list its files. We'll use "cd" to move down as well as up the directory structure.

The second way to list files in a directory, is to first move into the directory using the "cd" command (which stands for "change directory", then simply use the "ls" command.

I'll type "cd Downloads/Examples" to change directories into the "Examples" directory that is inside the "Downloads" directory.

Now, I can type "pwd" to verify that we're inside the "Examples" directory, and I can type "ls -al" to view the files and folders inside the "Examples" directory.

So, moving down into folders is pretty easy, but it might not be obvious how to move back up one level. You could type the entire path explicitly like "cd /Users/ModulesUnraveled/Downloads" but depending on how deep you are, that could quickly become obnoxious. This is where the "." and ".." come in.

The single dot represents the current directory, in this case the "Examples" directory. The two dots represent the directory that the current directory is inside, in this case the "Downloads" directory.

So, if we were to type "cd ." we would be changing directories to the one we're already in, which isn't very helpful. But if we type "cd .." we will be moved up one directory, into the "Downloads" directory. Let's give it a shot.

"cd .."

Now, if I type "pwd" you'll see that I'm inside the "Downloads" directory.

You might have noticed that just like the "ls" command could string directories with the "/", the "cd" command can as well. So, when I type "cd Examples/Example1/Test" I'll move all the way down into the Test folder directly. (I'll type "pwd" to verify that.) Likewise, typing "cd ../../.." will move me up three directories back up into the Downloads directory. (Again, I'll type "pwd" to verify that.)

Moving Into and Out of Directories with the "cd" Command (2024)

FAQs

How do you navigate to the moving around folder using the CD command? ›

The cd command allows you to move between directories. The cd command takes an argument, usually the name of the folder you want to move to, so the full command is cd your-directory . Now that we moved to your Desktop, you can type ls again, then cd into it.

What is the CD command used to change the directory? ›

The cd command, also known as chdir (change directory), is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.

What is the command for moving directories? ›

The mv command moves the file or folder from its old location and puts it in the new location.

How would you use the CD command to move back to your home folder? ›

Changing to another directory (cd command)
  1. To change to your home directory, type the following: cd.
  2. To change to the /usr/include directory, type the following: cd /usr/include.
  3. To go down one level of the directory tree to the sys directory, type the following: cd sys.

How do I navigate through a cd? ›

The cd (change directory) command moves you into a different directory. To move out of that directory, use cd along with the path to some other location, or use double dots to backtrack, or return home to navigate from there.

How do I cd directly into a folder? ›

In the command prompt window, type cd followed by the folder's name you wish to find. This only works for immediate folders straight after the one you're in. If you want to go back one directory, type cd .. to go up a level before typing cd to go back to the original option.

How do I change directories? ›

Open the Command Prompt (CMD) and type "cd" with a space, followed by the name of the directory, or drag and drop the directory into CMD from File Explorer. Press "Enter." Type "cd.." and press "Enter" to go back one directory. Type "cd\" and press "Enter" to go to the root of the drive.

How do I cd the current directory? ›

  1. To a Directory of Current Drive : To change the working directory, execute command cd followed by an absolute or relative path of the directory you are wanting to become the CWD.
  2. To a Directory of Another Drive : To change the working directory to another drive, execute command cd /D followed by a path to a directory.
Sep 30, 2020

Which command is used to change directory in disk operating system? ›

3.3 Command: Change Directory ( cd )

To change current working directory under the current drive, use command " cd new-path " (change directory).

What is the command for moving up a directory? ›

To change this current working directory, you can use the "cd" command (where "cd" stands for "change directory"). For example, to move one directory upwards (into the current folder's parent folder), you can just call: $ cd ..

How do I move files across directories? ›

Use the Move or Copy option

Alternatively, right-click the item and depending on what you want to do, select Move or Copy to folder. Select a folder from the drop-down list. If your folder isn't listed, select Move to a different folder (or Copy to a different folder).

How do I move between directories in Command Prompt? ›

To change the directory in Command Prompt (Cmd), use the “cd” command followed by the desired directory path, e.g., “cd C:NewDirectory.”

What is the CD command example? ›

The syntax of the 'cd' command is quite simple: cd [directory] . You replace [directory] with the name or path of the directory you want to navigate to. In this example, we used the 'cd' command to navigate to the '/var/www/html' directory.

How would you use the CD command to move into the Documents folder of your home folder Ubuntu? ›

The Tab key on your keyboard auto-completes names of directories and files you're starting to type. If you're going to cd into ~/Documents , then all you need to type is cd ~/Doc and then press Tab.

How do I move a folder to a cd? ›

File Transfer to CD/DVD
  1. Insert a blank CD.
  2. Double click on the CD drive under 'My Computer'
  3. Drag the files you wish to burn from Work In Progress to the CD drive's window.

How do you navigate to a folder in Command Prompt? ›

Place a backslash ("\") in front of each folder name. For example; "cd \Users\username\Documents." If you are not sure what the path of the folder is, you can navigate to the folder in File Explorer.

How do I move things around in a folder? ›

Move or copy an item using the clipboard
  1. Select the item you want to move or copy.
  2. To move, right-click and select Cut. To copy, right-click and select Copy. Alternatively, you can use the keyboard shortcut. ...
  3. Navigate to the folder where you want to move or copy the item to, and then click Ctrl+V.

How do I navigate between folders? ›

Use the arrow keys to move between files and folders. Press Enter to open a folder. Press the backspace key to go up a level in the file structure.

Top Articles
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6710

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.