Last Updated: February 25, 2016
·
756
· lokiastari

Bash: File from path

To convert a path into just a file (or last sectio of a path)

> path="/usr/local/some/long/path/to/end/partIwant"

Then you can retrieve it with:

> echo ${path##*/}
partIwant

Conversely if you want everything apart from the file:

> echo ${path%/*}
/usr/local/some/long/path/to/end

1 Response
Add your response

Also basename and dirname:

$ dirname /var/log/system.log
/var/log

$ basename /var/log/system.log
system.log

over 1 year ago ·