- Published on
How to get name of the current directory in Bash or Zsh
Sometimes, you might want to get the name of the current directory that you're working on.
In the bash/zsh shell script, you can use basename
basename
cli will give just the directory/file name depending on the input path that you're giving.
In our case, we can pass on $PWD
to get just the directory name like this:
full_path=$PWD # current working directory (eg: /Users/AshikNesin/Code)
directory_name=$(basename "$(dirname "$full_path")") #AshikNesin
Happy finding name!