DEV Community

@kon_yu
@kon_yu

Posted on

6 2

How to copy the path of the current directory to the clipboard (mac)

If you are in the current directory like /Users/user-name/sample/foo-bar in a terminal and want to open another terminal with the same path to open the same current directory, copy the path of the corresponding directory to the clipboard to make it easier.

Execute the following command in the directory you want to copy

pwd | pbcopy
Enter fullscreen mode Exit fullscreen mode

Open another terminal.
If you type "cd" and then paste the contents of the clipboard with cmd+v, the path of the current directory will be displayed.

cd /Users/user-name/sample/foo-bar
Enter fullscreen mode Exit fullscreen mode

pwd | pbcopy This command is broken down and explained.

pwd | pbcopy
Enter fullscreen mode Exit fullscreen mode

pwd Display the current directory (on standard output).

passes the contents of | output (standard output) to the input (standard input) of the following command

Copying from standard input to the clipboard on pdcopy mac.

Billboard image

Monitor more than uptime.

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (2)

Collapse
 
standiki profile image
Stanley Diki

It seems not to work on my elementary OS Horus 7.1, showing command not found.

Collapse
 
codemadeclear profile image
Bruno

Thanks for the article! I tried this and it worked, but a newline was appended at the end if the path. Any idea how I could get rid of the newline? What could I pipe the output through?

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay