Super User is a question and answer site for computer enthusiasts and power users. 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

Is it possible to do for exemple: ls -l * which print the content of all a directory. And add an exception, for exemple, test.cpp In order to print all files except the test.cpp.

share|improve this question
--hide or --ignore from the man page should work – Lamar B Feb 6 '12 at 16:29
up vote 3 down vote accepted

You can do it with a glob if you have extglob enabled. You can enable it with:

shopt -s extglob

And you can use it like:

ls -l !(test.cpp)

and it can be used in other ways, too:

ls -l !(*.jpg) # list all files that don't have .jpg extensions

Since this is a shell glob it can be used with other commands as well. One side effect, however, is that it causes any subdirectories to be listed explicitly, which means that ls would list them too. But, that can easily be handled with:

ls -ld !(test.cpp)
share|improve this answer

The classic (naive?) way to do this would be

  ls -l * | grep -v test.cpp

However, as Lamar commented, GNU ls has options for ignoring certain filenames

  ls -l -I test.cpp *

Note ls -l * lists files in the current directory and files in 1st level subdirectories. You may have meant ls -l without the *

share|improve this answer
Or maybe ls -ld *. – Daniel Beck Feb 6 '12 at 16:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .