basename and dirname bash builtins are handy and behave similar to their php based cousins. See here for application: http://bit.ly/cYDqHa