Skip to content
Advertisement

What does the “ls -A” option do in linux?

I was wondering what does the ls -A option do on it’s own and why does it work in the code below when checking if a directory is empty or not… ?

I can’t find any other answers online and the man pages I don’t understand what it means when I read the documentation.

Thanks

#!/bin/bash
FILE=""
DIR="/empty_dir"
# init
# look for empty dir 
if [ "$(ls -A $DIR)" ]; then
     echo "Take action $DIR is not Empty"
else
    echo "$DIR is Empty"
fi
# rest of the logic

Advertisement

Answer

Nothing related to bash. It tells ls to show all “hidden” files (those whose names start with .) except for . and .. (special directory entries representing the current directory and the parent directory, respectively).

Compare with ls -a, which shows all hidden files including . and ... The presence of those two entries in the output would make the directory appear to be not empty, even though it really is.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement