Select all files but one on linux

My friend wanted to know how to select all files but one on the CLI or in a bash script. This is how I normally do it, do you know a better way?

From the command line

ls * | grep -v [pattern to ignore]

or

ls [!pattern to ignore]  *

in a bash script it may look like this,


for i in `ls * | grep -v [pattern to ignore]`
do
   do something here
done


Leave a Reply

© 2008-2009 The Danesh Project
Powered by Wordpress and made by Guerrilla. Best viewed in Mozilla Firefox