Bash: Get Current Working Directory Name, but Not Full Path
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...
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?
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"