How to move up a directory with Terminal in OS X

So I used
OS X prevents you from copying files and folders to the root directory or your «Macintosh HD». Reverse this by typing:
basically resembles the root directory.

  • Switch to Root User
  • Logging In as the Root User
  • FAQs
  • Conclusion

Step 1: Open the Terminal application.

Use your preferred method to open the Terminal application. 

Type the command as shown below and then hit the return key.

How to move up a directory with Terminal in OS X

Step 3: Enter your password. 

Enter the password and hit the return key.

Step 4: Perform whatever tasks you need to perform.

How to move up a directory with Terminal in OS X
How to move up a directory with Terminal in OS X

Step 5: Exit 

How to move up a directory with Terminal in OS X

sudo su – root

How to move up a directory with Terminal in OS X

You will need to enter your password just as you did in the previous procedure. Notice in the above login, the prompt is slightly different. It still has the # symbol, but it does not have the color scheme or show the current directory. 

This is because it uses the root’s environment variables instead of my original environment variables. If we look at the current directory, you will also notice that we are now in the root’s home directory instead of the directory I was originally in.

How to move up a directory with Terminal in OS X

Below are some frequently asked questions about running Terminal as root.

sudo su root

Notice there is no – in this command. As with the other commands, you will also need to enter your password here.

What does sudo stand for?

Why Do I need to exit after working as root? Why not just work as root all the time?

Peter Mortensen's user avatar

asked Jul 16, 2010 at 17:44

JLeonard's user avatar

cd .. will back the directory up by one. If you want to reach a folder in the parent directory, you can do something like cd ../foldername. You can use the «..» trick as many times as you want to back up through multiple parent directories. For example, cd ../../Applications would take you to Macintosh HD/Applications

answered Jul 16, 2010 at 17:47

davidcelis's user avatar

1 gold badge18 silver badges16 bronze badges

For Mac Terminal

cd ..   # one up
cd ../  # two up
cd      # home directory 
cd /    # root directory
cd "yaya-13" # use quotes if the file name contains punctuation or spaces

shoover's user avatar

1 gold badge29 silver badges40 bronze badges

answered Apr 24, 2017 at 19:43

D88naimi's user avatar

3 silver badges5 bronze badges

Typing cd will take you back to your home directory.
Whereas typing cd .. will move you up only one directory (the direct parent of the current directory).

Peter Mortensen's user avatar

answered Nov 2, 2014 at 7:43

JSON C11's user avatar


7 gold badges78 silver badges65 bronze badges

To move up a directory, the quickest way would be to add an alias to ~/.bash_profile

alias ..='cd ..'

answered Jul 8, 2015 at 1:23

empedocle's user avatar

1 gold badge14 silver badges25 bronze badges

Let’s make it even more simple. Type the below after the $ sign to go up one directory:


Peter Mortensen's user avatar

answered Feb 12, 2015 at 8:09

Saral Kochar's user avatar

To go to the main/home directory using the below command

«cd ~/.» ==> without inverted commas

answered Aug 2, 2022 at 11:07

Basavaraj Baligar's user avatar

So here is a simple question whose answer has proved elusive. I recently installed a folder that I need to add some files to. The folder is stored in the «opt» folder I thought it would be as simple as:

But I can’t seem to find «opt». I can view the files in Finder, but I need to create some files and I’d rather do that on the command line. Can anyone give me some tips for accessing it?

asked Jul 13, 2016 at 2:05

Leia_Organa's user avatar

  • The opt folder in OSX is hidden by default
  • To make it visible in Finder, you would need to run this command
    defaults write AppleShowAllFiles YES;
    killall Finder /System/Library/CoreServices/;
  • Next, goto Finder and there you would be able to see the opt folder when you click on Macintosh HD.

  • opt is accessible in the Terminal anyways.

  • The command you are using is wrong I suppose

    myusername ~/opt/foldername
    myusername$ cd /opt/

To undo your changes, run these commands

    defaults write AppleShowAllFiles NO;
    killall Finder /System/Library/CoreServices/;

answered May 30, 2019 at 10:17

Sherwin Varghese's user avatar

  • Open Finder
  • Press Command+Shift+G to open the globally folder finder
  • Input the following search: /usr/local/opt
  • Click «Go»
  • open «Go to Folder»
  • Input the following search: /usr/local/opt

answered May 18, 2020 at 7:54

Saeed's user avatar

5 silver badges16 bronze badges

Based on your description, use /opt/foldername on the command line instead of ~/opt/foldername. The first form will access a folder off the root, the second will access a folder within your home folder.

Edit: because there was some confusion I’m pointing out here that /opt is as much a standard in UNIX-derived systems as /usr/local. They have slightly different purposes, but the difference is subtle (the full description is answered here if you’re interested). Using /opt is thus no less safe than using /usr/local, and it’s generally preferred over using a combination like /usr/local/opt that doesn’t get the distinction.

answered Jul 13, 2016 at 2:30

Feneric's user avatar

1 gold badge11 silver badges15 bronze badges

You can navigate to the file system on your Mac while in the Terminal application using the cd command.

cd <path and/or folder name>

My name is Eric, and as a software engineer for over 25 years, I have learned how to quickly navigate file and folder systems with command line tools such as Terminal. 

Дополнительно:  Как найти root explorer на телефоне

I will show you some of my preferred ways to do this and provide tips to make things easier, so keep reading.

  • Methods to Navigate to a Folder
  • Using a Path with the cd Command
  • Exploring your Disk with the cd command
  • Quick commands to help Navigation using cd
  • Two Methods using Finder
  • FAQs
  • Conclusion

You can use several methods to navigate to a folder in Terminal Mac. If you are using the Terminal application regularly, I recommend getting comfortable using the cd command. It’s one you will use a lot, and you should know.

There are also a couple of ways to use Finder from your desktop to get there, and this can be an excellent method when you need to do this quickly. As with any task on your Mac, it is always good to know multiple methods for accomplishing them. Let’s take a look at some now.

Using a Path with the cd Command

The cd command is the old reliable way to get to any folder on your file system. There are a couple of different scenarios to consider. The first is that you already know the path where your folder exists. For the second one, you don’t know the path and need to find it.

Let’s see how to do this in each situation. To get started, you need to open a session of your Terminal application.

You Know the Path

This can be pretty simple if you already know the path of the folder to which you want to navigate. All you need to do is plug it into the cd command, as shown below.

How to move up a directory with Terminal in OS X

Find the Path

In many cases, you won’t know the path to the folder you need to navigate to. In this situation, you will need to use some method to find it. You can use any of the same methods that you would use to find the path to a file. Below I will use the find command.

find / -name <foldername> 2>/dev/null

or for my example

find / -name WebArt 2>/dev/null

How to move up a directory with Terminal in OS X

Now I can select the path by highlighting it, then copy it, and then paste it to the end of my cd command.

How to move up a directory with Terminal in OS X

Exploring your Disk with the cd command

Sometimes we may not know the exact name of the directory we are looking for, or maybe we have an idea of what contents will be in the folder but don’t know the name of it. We may want to look around and explore what is in our file system.

In this case, I can use the cd command to traverse up and down the hierarchy of our file system. I can do this by specifying single folders within my current directory to move to. I’ll need to use the ls -l command to see what folders are in our current directory.

How to move up a directory with Terminal in OS X

If I want to move to the Test directory, I can use the cd command below.

How to move up a directory with Terminal in OS X

Once in the Test directory, I can also use the pwd command, as seen in the image above, to show the path of my current location.

Using the ls -l command again, I can now see the list of folders underneath the Test directory, which is my current directory.

How to move up a directory with Terminal in OS X

Here we see our WebArt folder used from the previous example. Now I can use the cd command again to move to this folder.

How to move up a directory with Terminal in OS X

I am now in the WebArt folder. This is an empty folder, but I have used the ls -la command to show the contents. The a parameter tells the system to show all contents, even hidden ones. Notice the . and the .. entries that are shown as directories.

How to move up a directory with Terminal in OS X

While it can take some time, you can use this method to traverse up and down the folder structure on your file system. Using the cd <foldername>, the ls command, and cd .., we can easily move around and get to anywhere we want to go.

Quick commands to help Navigation using cd

Once you begin using the cd command regularly, you will become more comfortable and learn tricks to make things a little easier and more natural. Below are some commands that can help you to get to where you are going quicker.

  • cd –  Go back to the previous directory you were just in.
  • cd .. Move back one directory level.
  • cd ~ Go to your home directory
  • cd    This will also take you to your home directory.
  • cd / Go to the root directory.
  • pwd shows your current directory
  • ls -la lists the continents of the current directory showing details and hidden files and folders.

Two Methods using Finder

Above, we have learned how to navigate to a folder using the command line in Mac Terminal. It is important to know how to use the cd command and the methods shown above to move around the file system, but you can use a few quick techniques when needed.

Drag and Drop

Step 1: Type cd and space in your Terminal window. (Do not hit return yet)

How to move up a directory with Terminal in OS X

Step 2: Open Finder using your preferred method.

How to move up a directory with Terminal in OS X

Step 3: Navigate to the folder that contains the folder you wish to go to in the Terminal. You can use the search feature if you are unsure of where it is.

How to move up a directory with Terminal in OS X

Step 4: Click on the Folder name in Finder and hold the left button down.

Step 5: Drag the folder over to your Terminal window.

Step 6: Release the left mouse button to drop the folder into the Terminal window.

How to move up a directory with Terminal in OS X

Step 7: Hit the return key in your Terminal window

How to move up a directory with Terminal in OS X

You will now be in the folder.

This method works well when you want to open up a new Terminal session in the location of the folder that you want to navigate to. Use finder to get to the location and right-click to bring up the context menu. From there, you can open a Terminal session, and you are there.

Below are a few questions often asked when learning how to navigate to folders in Terminal Mac.

Why do I see a Permission Denied message?

You may see a permission denied message if the folder you are trying to navigate to does not have read permissions or is not owned by you. You will need to change the folder’s permissions using the sudo chmod command with your password.

sudo chmod 777 <foldername>

You should now be able to cd to the folder.

Why do some paths have a ./ at the beginning, some have a /, and others just have the folder name?

Why does the find command show two different paths to my folder?

You can navigate to a folder in Terminal Mac in multiple ways. You should use the method that you find most comfortable but using the cd command is one that you should learn even if you prefer using finder with the drag and drop or context menu methods.

Have you found other ways that you like to use to navigate your Mac’s file system? I would love your feedback so let me know if you have any comments or questions.

Дополнительно:  Ноутбук включается и сразу выключается - Компьютерная помощь

If you are new to Mac Terminal and just learning some of the basic commands, it’s possible you may be feeling overwhelmed. Don’t worry, once you begin using it on a regular basis, things like changing directories will become second nature to you, and typing them in will be a breeze.

cd <file path>

I’m Eric, I have been around computers for over 40 years and I have worked as a software engineer for over 20. I have used command-line interfaces like Mac Terminal for much of that time and commands like cd are ingrained in my head so they come naturally to me.

While this command can be very simple, there are some things to know and look out for. Keep reading, and I will explain a bit further how to use it and give you some tips to make it a little easier to use.

  • What is the cd Command?
  • What is a Path?
  • Common Difficulties
  • Some Quick Tips and Tricks
  • Final Words

What is the cd Command?

As I mentioned above, the cd command, which stands for change directory, is one of the most commonly used commands in UNIX/LINUX-based command-line interfaces such as Mac Terminal. This is the command that is used to navigate the file systems that you have access to.

File systems are made up of a hierarchy of directories. The top directory is referred to as the root directory, and directories underneath that are called sub-directories. This can be seen on your desktop in finder when you look at the folder structure.

How to move up a directory with Terminal in OS X

In Finder, you can simply click down through the folders or subdirectories to get where you want to go but this is not possible from the command line. 

The cd command allows you to navigate down the subdirectories or back up the hierarchy to the root directory by typing in their paths.

What is a Path?

A path is just what the name indicates. It is a pathway or directions that you give to a command that tells your computer how to navigate or traverse the hierarchy of subdirectories to get to where you want to go in the file system.

How to move up a directory with Terminal in OS X
Example Directory Structure

From our example above, an absolute path might be

An example of a relative path would be if we are already sitting in the /Applications/newdevelopment directory.

App1/Logs       (notice there is no / before the path specification)

This path is relative to /Applications/newdevelopment

An easy way to tell the difference between an absolute path and a relative path is that an absolute path begins with a / and a relative one does not. This is because the absolute path always starts from the root directory which is defined as /.

Mac Terminal uses a UNIX/LINUX-based style of commands so paths are formed by putting the names of directories together with a / in between each directory name, with the root directory always being denoted as just the / by itself. 

If you wanted to move to the newdevelopment directory from anywhere on the file system, you could type:

Once in the newdevelopment directory, if you wanted to move to the App1 directory, you would only need to type

cd App1   (this uses the relative path)

But typing the absolute path will also work.

cd /Applications/newdevelopment/App1 (the absolute path) 

If I wanted to move to the decomm directory from this location I would either need to use an absolute path or I could specify upper level directories using the .. which stands for the parent directory. I will need to move up two levels in order to get to the decomm directory.

This means I would need to use two sets of .. separated by / which would result in the command shown below.

Remember that relative is relative to where you currently are in the structure. You can reach any location using a relative path as long as it is formed correctly by moving up or down the directory hierarchy, but in some cases, it’s easier to use the absolute path.

Nearly all errors that occur when using the cd command come from an improperly formed path. Many are just typing mistakes or leaving out a / somewhere, especially at the beginning of an absolute path, but most come from improperly formed relative paths.

Directory Does not Exist

Including a File in the Path

Another problem that some run into is adding the file name into the path. When trying to change directories using the cd command, the path cannot contain a filename because you cannot cd to a file, only to a directory location.

Spaces in the Path

One more common problem is accidentally (or purposely) having a space in your path. The command does not like spaces and this will cause it to fail. Some directory names do have spaces in them so you will need to use quotation marks to properly execute the command.

The cd command has only one parameter, the path. The key to ensuring your cd command works properly is ensuring your path is formed properly. Below are a few tips and tricks that can help you to move around your file system a little easier.

Some Quick Tips and Tricks

The cd command is quite simple but it is easy to make mistakes and can often require a lot of typing for long paths. Some of the tips and tricks below may help you to use it more efficiently. 

  • Type cd / to move to the root directory.
  • Type cd ~ to move to your home directory. 
  • Type cd .. to move up one directory level.
  • Use the .. to create relative paths. If I am in the App3 directory as shown above I can use cd ../App2 to move to the App2 directory. 
  • A single dot (.) Represents your current directory. 
  • Use cd – to move to whatever directory you were previously in.
  • Copy and paste whenever possible. This reduces the amount of typing which in return reduces typing errors. 
  • If a directory name in your path has a space in it, enclose the path in single quotation marks so that the space does not cause the command to fail.

The cd command is one of the most used commands when using Mac Terminal. It is what seems to be a simple command with only one parameter which is the path, but it can often turn complicated when trying to figure out the correct path and how you need to get to your location.

I hope the information I have provided above has helped you to learn how to use this command. As always, please let me know if you have any questions or problems.

How can I view the root directory along with all its subdirectories in Finder?

  1. Navigate to


    (e.g. use




  2. Then, in

    list view


    while clicking the triangle. This will show all subdirectories of a certain folder.
defaults write AppleShowAllFiles TRUE
killall Finder

You can use the value


in the

defaults write

command to unto this action.

How to move up a directory with Terminal in OS X

Finder — Preferences.
Check the box to show your Mac there, and you will be able to easily navigate wherever you want.

How to go back to root directory in command prompt, how to go back a line of comand in cmd. navigate home directory cmd. command prompt change directory backwards. back to previous repertory file in cmd. how to go back windows commandline. command line navigate back. navigate cmd path. windows cmd commands to go up. cmd go one folder up.

Дополнительно:  wanarp.sys Windows process - What is it?

How can i get default prompt and get rid of «sh-3. 2#»?

  1. Go to Preferences > Tools > Terminal
  2. click on the folder icon in Shell path
  3. Select your preferred, bash, zsh ect.
  4. Close and reopen terminal
echo $PS1

and then once you su in you can put it in your



PS1="\h:\W \u$ "

That way round, next time you login as root it’ll be picked up.

Thanks to Glados for pinpointing the default


on mac.

Ok i changed it to my wish finally!

su -> password
nano .bash_profile
export PS1="\u@\h\w $ "
CTRL - O -> Return -> CTRL - X

How to make root volume writeable again in Catalina?

Found this thread at Apple Developer Forums, where they do make their root directory writable again. This is not persistent across reboots, so you might want to create an script that runs at startup to make the change be permanent (don’t think this is necessary but would be a way out).

Original Answer:
  1. Disable SIP (recovery mode,

    csrutil disable


  2. Mount drive for read and write (

    sudo mount -uw /


  3. Enable SIP (recovery mode,

    csrutil enable


«sudo» in square brackets means it may be required (like in my case) while others report they managed to get result without it.

You can create a symbolic in root directory via


, as an example see below the creation of a symbolic link named




, which points to


, a writeable location at the root of the data volume.

echo -e 'bar\tSystem/Volumes/Data/bar' | sudo tee -a /etc/synthetic.conf

After executing the command above, you need to reboot to see effects.

man synthetic.conf

How to create a


directory you can write to:

  1. echo 'bar' | sudo tee -a /etc/synthetic.conf
  2. reboot
  3. Run the following commands:
sudo diskutil apfs addVolume disk1 APFSX Bar -mountpoint /bar
sudo diskutil enableOwnership /bar
sudo chflags hidden /bar  # Don't show the Bar volume on the desktop
echo "LABEL=Bar /bar apfs rw" | sudo tee -a /etc/fstab

Go to root directory in mac terminal

#With "cd + name of your folder" you can navigate into that folder

how to step back in the path in temrinal

cd ~ or cd -

how to change directory in terminal mac

cd <FolderName>

How To Access ROOT Directory of ANY MacBook Air / Pro! (MacOS), Own a MacBook Air or MacBook Pro & want to Access ROOT Directory? Learn how to get
Duration: 1:30

How To Access ROOT Directory of ANY MacBook Air / Pro! (MacOS)

Own a MacBook Air or MacBook Pro & want to Access ROOT Directory? Learn how to get
Duration: 1:30

How to go to home directory in Mac OS X Terminal

How to go to home directory in Mac OS X Terminal. 10,455 views10K views. May 4, 2016. 22

Duration: 1:17

MacOS Terminal (zsh) — The Beginners’ Guide

How does the macOS terminal work, why should I use it and what’s the difference between a

Duration: 30:51

How do I run terminal in sudo mode?

sudo -H npm "install" "." "--force" "--global"

That still makes the


command «root» and skips the log out step to get back out of root.

su kevin

when asked enter kevin’s password

sudo npm "install" "." "--force" "--global"

enter kevin’s password again.

[william@NCC-1701 ~]$ sudo su
[root@NCC-1701 /Users/william]$ 

If you haven’t used root before, you should be made fully aware that one wrong character typed as root will delete your entire operating system, including your photos, emails and financial documents. Be extremely careful and always triple-read what you type before hitting enter. Otherwise, good luck!

How to view Root directory and subdirectories in Finder?, Pressing Command+Up will go up 1 level to reveal the root directory.

Open Terminal Here, as Root (OS X)

It was actually quite complicated to figure out, but I ended up adding this to my



if [ -d "$directory" ]; then
    cd "$directory"

After that I used the «Open Terminal Here» script and simply modified it so that it copies the current path to the clipboard before launching the terminal

    tell application "Finder" to set the clipboard to the_path

and then I added the

sudo -i

part to the code where it activates terminal:

    set cmd to "cd " & quoted form of the_path & " && echo $'\\ec' && sudo -i"
    tell application "Terminal"

So, the path will be copied to the clipboard, I can use an icon to launch the applescript, and then when the profile is loaded (for root) it will change to the directory.

What’s the directory you’re trying to get to? The home alias (‘~’) doesn’t work as root, so you might need to use an absolute path.

tell application "Terminal"
    tell application "System Events" to keystroke "sudo -i" & return
    do script with command cmd

More generally, you can get AppleScript to do sudo commands with code like this:

set shellOutput to do shell script cmd with administrator privileges
display dialog shellOutput

where ‘cmd’ is the command to run. (This also displays a popup of the code results.)

Return to previous directory terminal Code Example, Linux command to go root directory from any directory. how to go back to previous directory in ubuntu terminal · return to previous directory command prompt

How to view Root directory and subdirectories in Finder?

Enter in Terminal:

sudo chflags nohidden directoryname

Whereby directory name is the name of the directory that you want to see in Finder.

Reverse this by typing:

sudo chflags hidden directoryname


Macintosh HD

basically resembles the root directory. If you want it to appear on the desktop and in finder change this in the finder preferences.

Showing all files in Finder

Type in the terminal

defaults write appleshowallfiles true

Then log out and back in.




in Finder brings up a «Go to folder» dialog. Type in the name of the directory, for example,


. Finder will show the directory. I use this with Finder in ‘View as Columns’

While this doesn’t give a browsable directory from the root directory down, I’ve found it quite useful.

But that will make


in the root directory visible.

Personally, I didn’t want to make everything visible, just the /usr directory.

So I used

sudo chflags nohidden /usr

Copy a file to the root directory

Simply open up the Terminal application. You can use Spotlight to search for it or go to your Applications folder, then Utilities folder.

Once in Terminal, you’ll be faced with a prompt.

Run the command below to put the file or folder in your root directory. Put the name of the file or folder in place of «FILE».

sudo cp -p Desktop/FILE /

Press the return key. You’ll be prompted for your password.

If you are required to change the owner or permissions of the file, you can run a command like


change owner or


change group or


change file permissions.

Оцените статью
Master Hi-technology
Добавить комментарий