0

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!

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.

1
#!/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

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