Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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"
share|improve this answer
Also basename ~+ – Steven Penny Nov 26 at 19:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.