LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-23-2005, 04:06 AM   #1
Registered: Aug 2003
Location: Europe
Distribution: RHEL 7.x, 6.x, Fedora 20, Kubuntu 12.04
Posts: 322

Rep: Reputation: 17

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 :-(

Matches anything except one of the given patterns

Old 01-23-2005, 04:26 AM   #2
Senior Member
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
Old 01-23-2005, 04:27 AM   #3
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
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:
ls *2004* | grep -v ".bz2"
Old 01-23-2005, 05:33 AM   #4
Registered: Aug 2003
Location: Europe
Distribution: RHEL 7.x, 6.x, Fedora 20, Kubuntu 12.04
Posts: 322

Original Poster
Rep: Reputation: 17
~> 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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
copy problem using wildcards plisken Linux - General 11 11-16-2005 08:34 AM
Handling wildcards... artificialGekko Linux - General 5 03-24-2005 08:29 PM
CLI wildcards ShakyJake Linux - Newbie 4 02-28-2005 03:42 PM
ls command line, color and wildcards ioio85 Linux - Newbie 1 05-13-2004 05:01 AM
Wildcards in kernel Squall Linux - General 1 04-20-2004 05:22 PM

All times are GMT -5. The time now is 11:36 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration