LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Wildcards (https://www.linuxquestions.org/questions/linux-newbie-8/wildcards-281130/)

dazdaz 01-23-2005 04:06 AM

Wildcards
 
I wanted to find all files with 2004 in the name, but not the files that are compressed with bzip, and so have the .bz2 extension.

I thought that something like this would of worked but it did'nt.

$ ls -l *.2004*{\!\.bz2}

Is there a really good guide on the web on wildcards, because I need to re-read it and learn more about this, I don't understand it as thoroughly as I first thought. I can't find it in the ls / bash(shell expansion) manpage.

In fact "man bash" just says this with no examples :-(

!(pattern-list)
Matches anything except one of the given patterns

Thanks

320mb 01-23-2005 04:26 AM

http://www.ss64.com/bash/index.html

Dark_Helmet 01-23-2005 04:27 AM

Shot in the dark here, but are you sure you enabled the extglob shell option? The paragraph above the list of extended file globbing (all the ?(), *(), +(), @(), and !() business) says that those extended pattern matching operators only work if extglob is enabled using the shopt builtin command. To see a list of what your shell has enabled, execute shopt with no arguments. Check for extglob, and it should say either Off or On.

Another way to do what you're after without messing with shopt, is good old grep:
Code:

ls *2004* | grep -v ".bz2"

dazdaz 01-23-2005 05:33 AM

~> shopt | grep extglob
extglob off
~> shopt -s extglob
~> shopt | grep extglob
extglob on

~/z> ls -l
total 0
-rw-r--r-- 1 ddd zz 0 Jan 23 10:38 abc.2004
-rw-r--r-- 1 ddd zz 0 Jan 23 10:38 abc.2004.bz2
-rw-r--r-- 1 ddd zz 0 Jan 23 10:38 abc.2004.gz

# Then this can work

~/z> ls -l !(*.bz2|*.gz)
-rw-r--r-- 1 ddd zz 0 Jan 23 10:38 abc.2004

This has turned into a good learning exercise. Thank you !

I guess there are some very good shell functions that people have wrote to use with this option.


All times are GMT -5. The time now is 06:14 PM.