How to exclude blacklisted files from ls?
I have a file blacklist
:
$ cat blacklist Iran Iraq Libya Somalia Sudan Syria Yemen
How can I exclude the files listed in this file blacklist
from the output ls
? I have read the man pages and the closest is the parameter --ignore
, which unfortunately does not read the file. I also thought about piping the output ls
to grep
and using an option --invert-match
to ignore all files in the file blacklist
, but I don't know how.
source to share
If you need to use ls
, you can do this:
ls | grep -vFxf blacklist
-
-v
to invert selection -
-F
treat lines from the file blacklist as strings, not patterns -
-x
to match the whole string -
-F
to read from the blacklist for patterns / strings to match
Please note that the above solution works in all cases, except when the filenames have newlines in them.
source to share