dirname basename path

basename
it will delete any prefix up to the last slash ('/')
basename will retrieve the last name from a pathname ignoring any trailing slashes
$ basename /home/jsmith/base.wiki 
base.wiki

$ basename /home/jsmith/
jsmith

$ basename /
/
basename can also be used to remove the end of the base name, but not the complete base name
$ basename /home/jsmith/base.wiki .wiki
base

$ basename /home/jsmith/base.wiki ki
base.wi

$ basename /home/jsmith/base.wiki base.wiki
base.wiki


dirname
 it will delete any suffix beginning with the last slash ('/') character and return the result

$ dirname /home/martin/docs/base.wiki
/home/martin/docs

$ dirname /home/martin/docs/
/home/martin

$ dirname base.wiki
.

$ dirname /
/

Comments

Popular posts from this blog

HAproxy logging

tomcat catalina coyote jasper cluster

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all