Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

This question already has an answer here:

I have a file with a list of directories and I need to find out if they actually exist on the system. It's quite a large list so I'd like to figure out how to automate the check.

The file is formatted with each directory on a new line:

/usr/bin
/usr/sbin
/bin
/sbin

Any suggestions? Thanks!

share|improve this question

marked as duplicate by Christopher, Jeff Schaller, GAD3R, HalosGhost, Ramesh Nov 14 '16 at 17:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted
#!/bin/bash

while read -r dir; do
    if [[ -d $dir ]]; then
        echo "Dir exists"
    else
        echo "Dir $dir does not exist"
    fi  
done < dirs

Output on execution with this file as infile (dirs):

cat dirs
/usr/bin
/usr/sbin
/bin
/sbin

./checkDirs.sh 
Dir exists
Dir exists
Dir exists
Dir exists
share|improve this answer
    
Thanks! That did the trick. – popcornuk Nov 14 '16 at 16:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.