0

Why does ls --ignore not ignoring the pattern?

Looking at the below example:

mkdir books
cd books
touch books_abby.csv
touch books_karen.csv
touch books_david.csv
touch books_tom.csv

This creates four files:

$ ls
books_abby.csv  books_david.csv  books_karen.csv  books_tom.csv

If however you want to ignore all filename containing "tom" and list them, books_tom.csv is still returned:

$ ls *.csv --ignore="*tom*"
books_abby.csv  books_david.csv  books_karen.csv  books_tom.csv

The expected outcome is for files containing "tom" to be omitted:

$ ls *.csv --ignore="*tom*"
books_abby.csv  books_david.csv  books_karen.csv
0

The --ignore option of ls seems to be OK and working, but the problem seems to occur when you mix it with *.csv in the same ls command.

So, you can get the same result using (since all your files end with .csv):

$ ls *.csv --ignore="*tom*"
books_abby.csv  books_david.csv  books_karen.csv

If you have other files extensions that you don't want to show up in the output, you can try:

$ ls !(*tom*).csv
books_abby.csv  books_david.csv  books_karen.csv

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.