Get Current Directory Name Without Path In Bash

Posted by Weston Ganger on April 01, 2016

I was writing a script and wanted to get the current directory name without the path.

Heres a few ways to do this in Bash.

# Simple way to print it
echo "${PDW##*/}"

# More complicated but more reliable in case of weird directory names
printf '%s\n' "${PWD##*/}"

# Assign to a variable

Related External Links:

Posted in Linux and Tagged with bash script linux command-line 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts