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
Greg
  • 1,657
  • 5
  • 27
  • 38

1 Answers1

1

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
Khaled
  • 36,533
  • 8
  • 72
  • 99