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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
1  
Also basename ~+ – Steven Penny Nov 26 '15 at 19:05

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.