Get Current Directory Name Without Path In Bash

Posted by Weston Ganger

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:

Article Topic:Software Development - Linux

Date:April 01, 2016

Recommended Posts



Send Me A Message

I would love to get in touch and talk about your next project. Feel free to send a message and I will get back to you shortly.

Get Connected