Bash: get current working directory name, but not full path
By David Jones •
I know that pwd will print the full path of current working directory, but I want to print only the name of the directory. Is there a simple command to do this without to parse pwd?
1 Answer
Yes, there is. You can use pure bash:
echo "${PWD##*/}"or better, to avoid the case when you could be in -e directory:
printf '%s\n' "${PWD##*/}"(thanks to @gniourf_gniourf for the second suggestion).
Or you can use basename tool:
basename "$PWD" 3 More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"