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
Written by LokiAstari
Related protips
1 Response
Also basename and dirname:
$ dirname /var/log/system.log
/var/log
$ basename /var/log/system.log
system.log
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#