Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 have found an error in monit init script that I want to fix on my own for now. The faulty code is

PID_DIR=$(/bin/basename "$MONIT_PID_FILE")
/bin/mkdir -p -m0700 "$PID_DIR"

The developer wants to create the directory /var/run/monit from $MONIT_PID_FILE that equals to /var/run/monit/, but unfortunately basename returns the file name, not directory path. This causes the directory not being created and monit not starting.

How can I get a file's directory full path starting from the file's full path? ie. /usr/local/myfile.f => /usr/local

share|improve this question
up vote 3 down vote accepted

Use dirname to get the directory path (instead of using basename).

Refer: dirname

share|improve this answer

Your Answer


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.