Everything about File or Folder Path on Mac



Series: Awesome Tips about Mac

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

  • 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.
  • After select a folder, choose “Services - > New iTerm2 Tab”.

Assign Keyboard Shortcut to “New iTerm2 Tab” at Finder

  • Go to System “Preferences -> Keyboard -> Shortcuts”, choose “Services” in the left panel, find “New iTerm2 Tab” and assign a shortcut like: Ctrl+Option+i.
  • To check whether the shortcut assignment works, we can go to Finder menu, Finder -> Services, check whether the new shortcut is shown for the “New iTerm2 Tab” menu item.
    • If the shortcut is not there and doesn’t work, it’s often because the shortcut we choose conflicts with other existing shortcuts.
  • Now we can Ctrl+Option+i to open a new tab for any file at Finder.

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)