Copy a File or Folder Path from Context Menu

Right click on a file to show the context menu, hold Option(⌥) key, “Copy xxx” will be changed to “Copy xx as Pathname”.

Copy a File or Folder Path at Path Bar

First go to Finder -> open View menu, check “Show Path Bar”, then right click at the path bar at the bottom, choose “Copy xx as Pathname”.

Get File or Folder Path at iTerm2(or Terminal)

If we want to get the file or folder path in Terminal, “Ctrl+C” to copy the file or folder in Finder, then paste it into the Terminal: it will paste the full path (all special characters are already escaped, so no need to add " ").

Go to the Parent Folder (of a File or Folder) at Iterm2(or Terminal)

To go to the parent folder of a folder or especially for a file:

First let’s define the following pcd command in ~/.bash_profile which will go to the parent folder of the file; then source ~/.bash_profile function pcd () { cd " $( dirname " $1 " ) " ; pwd ; }

Then “Ctrl+C” at the selected file in Finder, then in Terminal type pcd, space, then paste the file.

“New iTerm2 Tab” in Finder

I use iTerm2 as my default Terminal, but the approaches for iTerm2 would also work for the default Terminal.

After select a file, choose New iTerm2 Tab in the context menu, it will create a new tab and cd to the enclosing folder.

in the context menu, it will create a new tab and cd to the enclosing folder. After select a folder, choose “Services - > New iTerm2 Tab”.

Assign Keyboard Shortcut to “New iTerm2 Tab” at Finder