Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 4 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

Your Answer

 
discard

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.