How to Go Back One Directory in macOS Terminal (OS X)

Use the cd .. command to move up one directory level in macOS Terminal.

The cd (change directory) command is fundamental to navigating the file system in Unix-like operating systems. Whether you are working in the CPython source tree or managing local projects, knowing how to go back one directory in macOS Terminal (OS X) is an essential skill for developers and system administrators.

Understanding the cd .. Syntax

On macOS, the default shell is zsh (or bash on older OS X versions). The command to change directories is cd, and the argument .. represents the parent directory of your current location.

When you execute:

cd ..

The shell updates your current working directory to the immediate parent folder, regardless of where you are in the file system hierarchy.

Practical Examples for Navigating Up One Directory

Moving Up One Level

To simply go back one directory:

cd ..

After execution, your prompt will reflect the new location. You can verify this with the pwd (print working directory) command.

Verifying Your New Location

Always confirm your position after navigation, especially before running build commands:

cd ..
pwd

This outputs the absolute path of your current directory, ensuring you are in the correct parent folder.

Combining Commands

You can chain navigation with other operations using &&:

cd .. && ls

This moves up one directory and immediately lists the contents of the parent folder.

Returning to the Previous Directory

To toggle between your current location and the directory you just came from (undoing the last cd):

cd -

This is particularly useful when you need to temporarily check a file in a parent directory and then return to your working folder.

How CPython Uses Directory Navigation

The CPython source tree demonstrates standard terminal navigation patterns in its build documentation. In the repository's README.rst, build instructions illustrate moving into a subdirectory and then referencing the parent directory to run configuration scripts:

mkdir debug
cd debug
../configure --with-pydebug

Here, ../configure uses the .. notation to execute the configure script located in the parent directory (the repository root) while the current working directory is debug/. This pattern appears throughout the CPython development workflow, including in Doc/README.rst for documentation builds and when navigating between Misc/NEWS.d and the top-level directory.

Summary

  • Use cd .. to move up one directory level in macOS Terminal.
  • Verify your location with pwd after navigation to avoid running commands in the wrong directory.
  • Use cd - to quickly return to the directory you were in previously.
  • The .. syntax represents the parent directory in all Unix-like shells, including zsh and bash on macOS.

Frequently Asked Questions

What is the difference between cd .. and cd -?

The command cd .. moves you up one level to the parent directory of your current location. The command cd - switches you back to the previous directory you were in, regardless of its location in the file system hierarchy. Use cd - as an "undo" for the last directory change.

Can I move up multiple directory levels at once?

Yes. To move up two levels, use cd ../... For three levels, use cd ../../.., and so on. Each .. represents one level up the directory tree. You can also combine this with directory names, such as cd ../sibling-directory to move up one level and then into a different folder.

Why does cd .. work in both bash and zsh on macOS?

Both bash and zsh are POSIX-compliant shells that implement the same standard for directory navigation. The .. notation for parent directories is defined by the POSIX standard and the underlying Unix file system, not by the shell itself. Therefore, cd .. behaves identically across all standard shells on macOS and Linux systems.

How do I navigate up one directory in Python scripts?

In Python, use the os or pathlib modules to change directories programmatically. With os, call os.chdir('..'). With pathlib, use os.chdir(Path('..').resolve()) to move up one level and resolve the absolute path. This mirrors the terminal behavior but allows navigation within your Python programs.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →