Reputation: 125
I've been working with a regex that finds the directories from a 'ls -lF':
sed -n '/\/$/p'
Now, I want this to work with NOT directories (i.e. files, but not symlinks). How should I do it?
Upvotes: 0
Views: 64
Reputation: 531345
Don't try to parse ls
. Use the appropriate predicates with the find
command, or look at the primaries available with the test
command.
find . ! -type d
or
for f in *; do
if ! [ -d "$f" ]; then
echo "$f"
fi
done
Upvotes: 1
Reputation: 37288
ls -lF | sed -n '/\/$/!p'
# --------------------^------
As in many places in Unix, ! negates a test. Or maybe you're familiar with -v
negation in the grep
family of tools.
IHTH
Upvotes: 0