Copy Current Path from Terminal Mac
In this article
To copy the current path from Terminal on a Mac, you can use the pwd command to print the working directory, then select the output with your mouse or trackpad and press Command+C. For a faster method, you can use the keyboard shortcut Command+Shift+C after selecting the path, or use a command like pwd | pbcopy to copy it directly to your clipboard without manual selection.
Why You Need the Current Path
Knowing the full path of the directory you're working in is essential for many tasks: writing scripts, moving files, setting environment variables, or sharing a location with a colleague. Terminal shows only the short folder name in its prompt by default, not the full path, so copying it correctly saves time and avoids typos. The path is the sequence of folders from the root (/) to your current location, like /Users/yourname/Documents/Projects.
Using pwd to Print the Path
The simplest way to see the current path is to type pwd (print working directory) and press Return. Terminal then displays the full path on a new line. To copy it, you can:
- Click and drag to highlight the path, then press Command+C.
- Triple-click the path to select the whole line, then press Command+C.
- Use the keyboard shortcut Command+Shift+C after selecting (this is a Terminal-specific copy that preserves formatting).
This works in any version of macOS Terminal. The path is plain text, so you can paste it into any application with Command+V.
Copying Directly to Clipboard with pbcopy
For a one-step copy, combine pwd with the pbcopy command:
pwd | pbcopyThis pipes the output of pwd into pbcopy, which places it on the clipboard. You can then paste it anywhere. This is especially useful when you need the path frequently or when you're writing a script that requires the path as a variable.
If you want to copy the path of a different directory without changing to it first, use cd with pwd in a subshell:
cd /some/other/dir && pwd | pbcopyThis changes to that directory, prints its path, and copies it, all without affecting your current Terminal session.
Dragging a Folder into Terminal
Another practical trick: drag any folder from Finder into a Terminal window. Terminal automatically inserts the full path of that folder, with spaces escaped as or depending on your settings. You can then copy that text. This works for files too, and it's often faster than typing or using pwd when you need a path outside your current directory.
Alternative: Using the Terminal Menu
If you prefer menus, you can use the Edit menu in Terminal. After selecting the path text, go to Edit > Copy or press Command+C. There's also Edit > Copy Special which offers options like copying as a quoted string or as a path with no escaping. These options are handy when you need the path in a specific format for a script or command.
Common Problems and Solutions
Users often run into a few issues when copying paths:
- Path has spaces: When pasting into a command, you may need to quote it:
cd "/My Folder/Sub Folder"or use backslash escapes.pbcopycopies the raw path, so you'll need to add quotes manually if required. - Path is too long to select: Use
pwd | pbcopyto avoid manual selection errors. - Terminal doesn't show full path: By default, the prompt shows only the current folder name. Use
pwdto see the full path. - Copying from a remote server: If you're SSH'd into another machine,
pwdgives the remote path, not your local Mac's path. You'll need to copy the remote path separately.
Comparing with Finder's "Copy as Pathname"
Finder offers a similar feature: right-click a file or folder, hold the Option key, and choose Copy as Pathname. This copies the full path to the clipboard. However, it includes the folder name and uses a forward slash format, which is the same as Terminal's output. The Terminal method is more direct when you're already in the directory, and it avoids leaving Terminal to use Finder.
Frequently Asked Questions
How do I copy the current path without typing pwd every time?
You can create a shell alias or function. For example, add this to your ~/.zshrc (or ~/.bashrc for bash): alias cpwd='pwd | pbcopy'. Then typing cpwd copies the path instantly.
Why does the path have a tilde (~) in it?
The tilde is a shortcut for your home directory (/Users/yourname). When you see ~/Documents, it means /Users/yourname/Documents. The pwd command always prints the full absolute path, not the tilde version.
Can I copy the path of a file in Terminal?
Yes. If you're in the directory containing the file, type pwd and then append the filename manually, or use echo "$(pwd)/filename" | pbcopy. Alternatively, drag the file into the Terminal window to get its full path.
Is there a way to copy the path without the trailing newline?
By default, pwd outputs a newline. When you copy with pbcopy, the newline is included, which can cause issues if you paste into a command. To remove it, use printf %s "$(pwd)" | pbcopy or pwd | tr -d '\n' | pbcopy.
Does this work in other terminal apps like iTerm2?
Yes, the pwd and pbcopy commands work in any terminal emulator on macOS. iTerm2 also has a built-in feature: Edit > Copy Special > Copy the Current Directory or the shortcut Command+Shift+C.
What if I want to copy the path in a script?
In a shell script, you can assign the path to a variable: current_path=$(pwd). Then use echo $current_path or pass it to other commands. To copy to clipboard, use echo $current_path | pbcopy.