Bash - Get Name of Parent Directory

  • Posted on: 2 March 2016
  • By: davis

For the path /foo/bar/, if the current directory is bar, and we want to get the name of the parent directory (i.e. foo)

path="$( cd "$( dirname $0 )" && cd -P "$( dirname "$SOURCE" )" && pwd )"
parentName=$(basename -- "$(dirname -- "$path")")
echo $parentName # will return parent directory's name

This resolves symbolic links (sidestepping the error where it returns "." for the parent dir). Give it a try.

shittalk.cfg - Home Of The Dumbest Binds In Video Gaming

  • Posted on: 29 October 2014
  • By: davis

Have you ever been playing an online FPS and wished you could say something unintelligible, idiotic, and just plain stupid?

Have you ever wished that with one click, you could make people think you were mentally unstable?

Have you ever wished that you weren't literate and also had seizures while typing?

Have you ever  wanted to accuse your opponents of exploiting waterfall bugs in a game that doesn't have waterfalls?