Keep last directory from path

Hello,

I am looking for a command that will give me the last directory name from a path

ex 1 :

/dir1/dir/2/dir3/

output needed

dir3

ex 2 :

/dir1/dir/2/dir3/dir4/

output needed

dir4

Thanks

Use this:

basename /dir1/dir/2/dir3/
1 Like