How to check if directory is not containing hidden dir and one specific dir

I'd like to see if "/tmp" dir contains hidden dir and dir named "test"

Currently ls -la /tmp contains below

.
..
test

I'd like to check if /tmp doesn't contain anything else besides above using shell script?

0

1 Answer

You could use this command to list any hidden directories and avoid listing "." which refers to directory itself.

find /tmp -maxdepth 1 -type d -iname ".*" -a -not -name "."

Output of this command can either piped to grep or used in a variable and tested with [ -z "$VAR" ] to check if the string is empty. If it is, there's no hidden directories

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like