Monday, October 10, 2022

[SOLVED] How to get the path part of a full file name with macOS bash?

Issue

Edit I am still wondering why this question is closed. Parent is not what I was looking for. Maybe somebody can explain why this question is not opened again? Thank you.

This question has nothing to do with "parent"! So, I do not know why the question was closed and an answer for a parent directory was mentioned.

A question about bash on macOS

I have a file name which is something like

/Users/johndoe/Desktop/folder/file.txt

But I only need the path part

/Users/johndoe/Desktop/folder

with or without the last /, both is OK.

I have no idea how to do it, so I can't provide anything I have tried.

//Edit: There is a discussion now if I asked for the parent path or not. I didn't. Here is the definition what a parent path is.


Solution

dirname /Users/johndoe/Desktop/folder/file.txt


Answered By - Alex028502
Answer Checked By - Cary Denson (WPSolving Admin)