Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
--hide or --ignore from the man page should work –  Lamar B Feb 6 '12 at 16:29

2 Answers 2

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

Your Answer

 
discard

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.