Issue
I need to remove the root directory from a file path. Below is the example for the same,
path1=/tmp/errorlog_invest_12345_88_1:05:45.txt
Output:
The root directory here is /tmp/
Moreover i wanted to do this in a dynamic manner i.e. identify the root directory for any file path given.
Kindly help me on this. Thanks!
Solution
Judging by your string, you're probably using bash.
You can split the "root" from the path with the dirname -command. Example:
dirname /tmp/errorlog_invest_12345_88_1:05:45.txt
This should print: tmp ... as result.
Answered By - DocWeird Answer Checked By - Mary Flores (WPSolving Volunteer)