Linux Commands - ls (list) --ignore

by
Jeremy Canfield |
Updated: October 20 2020
| Linux Commands articles
Let's say the /tmp directory contains the following files.
/tmp/foo.txt
/tmp/bar.txt
/tmp/hello.txt
/tmp/world.txt
The ls (list) command with the -I or --ignore option can be used to list the contents of the /tmp directory, ignoring certain files. In this example, the foo.txt file will be ignored.
#]$ ls /tmp --ignore foo.txt
/tmp/bar.txt
/tmp/hello.txt
/tmp/world.txt
In this example, both foo.txt and bar.txt will be ignored.
#]$ ls /tmp --ignore foo.txt --ignore bar.txt
/tmp/hello.txt
/tmp/world.txt
However, when you want to ignore two or more files, this is a much better approach.
#]$ ls /tmp --ignore={foo.txt,bar.txt}
/tmp/hello.txt
/tmp/world.txt
Did you find this article helpful?
If so, consider buying me a coffee over at