DEV Community 👩‍💻👨‍💻


Posted on

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

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

pwd | pbcopy This command is broken down and explained.

pwd | pbcopy

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.

Oldest comments (1)

codemadeclear profile image

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?

🌚 Life is too short to browse without dark mode