How to Change Directory in Terminal on Mac

Mac users use terminal for many purposes. The terminal is really helpful for mac user but if you are a new user then you may don’t know how to use it to do different tasks. We can perform many different tasks using terminal. But for now we will be discussing how you can change directory in terminal on mac.

When we work in a command-line environments like mac terminal, we often needs to change directories. The directory is just a two-word command (cd <file path>)that we can use to change it but changing it in a mac terminal can be little tricky. So’ let’e see how we can change directory in terminal on mac.

let’s get into it.

What is path

Every folder of file have its own unique address that is called path. The path tells the computer where the file or folder is stored in the computer. There is a hierarchy in which the path is followed. A path must follow the hierarchy.

The path is of two types: absolute and relative Path. The difference between both paths is absolute path start from the root directory while the relative path is given from your current location. So, the relative path will always be relative to you.

For example: /Applications/Webdevelopment/CRM/logs

The above path is relative path. If the path starts from the / then the path will be the absolute and if the path don’t start with / then the path will be relative. As /applications/webdevelopment will be absolute path and crm/logs will be called as relative path because the crm/logs is connected with the absolute path.

How to Reset Admin Password on Mac With Terminal

What is cd Command

The CD command is normally called as Change Directory. The CD command is really common used in UNIX/LINUX command interface. And Mac terminal is also a command line interface. The CD command used to change directory in terminal on mac.

In a hierarchy, the top directory is the root directory while the next path is called sub-directories. You can see this in your finder when you look as folder structure.

How to Change Directory in Terminal on Mac

To change directory in terminal on mac, we will be using the CD command in the terminal. This will allow us to go to different folder and locations.

For example: if we want to go to desktop we will use CD desktop command and same like this if we want to see what is in the folder we will use LS command and PWD command to see the full path of a folder.

How to Go Back From the Directory using Mac Terminal

If you want to go back from the directory using terminal, you can go use different commands. To go back you an use CD command and if you want to PWD command to see the path of the current folder. If you want to return to the root address, you have to use CD command without any argument

Common Difficulties During Changing Directories in Terminal

There are some common difficulties users face during changing the directories in terminal. Some of them are these

Directory Does Not Exist

Sometime the directory you are searching does not exist in your computer. Also, it may not exist at the location you are searching the location maybe changed. This cause an error during finding the directory

Typing Mistake

The directory you are searching may exist but during typing address you may have written the address wrong. Many people write the address without / or leaving it within the address can cause the error.

Spaces in the Path

This mistake is also common that you r address contain a space that is not possible in any directory address. When your address contain a space it is the wrong address. You can use the quotation mark to properly execute the command.

There is only one parameter in the cd command that is the correct path of directory. If you enter the correct directory path and the directory is also available in the computer then you are good to go.

How to Reset Admin Password on Mac With Terminal

Quick Tips and Tricks

The CD command is easy to use and we can easily move to different directories in the mac but as you have seen above, there are a lot of mistakes that happen in this. Also, this requires a lot of typing and this causes the typing mistakes.

Below commands can help you to use it more efficiently.

  • To go to Root Directory, use CD / command.
  • To go to home directory, use CD ~ command.
  • To move up one directory, use CD .. command.
  • Use CD – to move your previous directory.
  • A single dot represent your current directory.

You can copy and paste to reduce the typing mistakes. In return, the chances of error will also reduce. If you have space in your directory, you can enclose the single quotation marks so your command don’t fail due to space.

Umar Farooq
Umar Farooq
Umar Farooq is a digital Evangelist having right commands on writing, also he is a web developer. He has a BS(Computer Science) and now he is Full-Time writer of TechanZone.

Popular on TechanZone


Please enter your comment!
Please enter your name here