Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to run ls and exclude certain files in the output.

When I run the following command, I get all files with each on one line:

$ ls -1

I would like to run this command in a way so it shows

$ ls -1 <insert magic here> temp
share|improve this question
up vote 22 down vote accepted
ls -I <filename>

-I = Ignores the file. It won't list the specified file.

To ignore more than one file add multiple -I before files.

ls -I file1 -I file2
share|improve this answer
If you use the long-form option --ignore you can extend that to glob patterns e.g. ls --ignore="file?" or ls --ignore="file*" – steeldriver Aug 18 '14 at 15:23
Thank you. ls -I "file*" also working. – Sudheer Aug 18 '14 at 15:42
you can use glob patterns with the short form as well by quoting the patterns – verboze Dec 29 '15 at 5:42

For me if I use -I once, it works but if I use twice it doesn't. e.g: ls -I *.csv works.

But ls -I *.csv -I *.txt doesn't work and returns txt files instead.

--ignore did the trick for me. This is what I needed and worked.

ls -lhrt --ignore="*.gz" --ignore="*.1"

That will list me files from log folder where it exclude old backup logs.

share|improve this answer
quoting *.csv in the first form works, e.g.., ls -I '*.txt'. The reason it doesn't work unquoted is because of shell expansion, i.e. you're telling the shell to list all csv files instead of excluding them. What's actually happening is that it ignores the first .csv and .1 files after expansion, but lists the remainders – verboze Dec 29 '15 at 5:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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