LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-23-2005, 04:06 AM   #1
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL, CentOS, Ubuntu
Posts: 333

Rep: Reputation: 17
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
 
Old 01-23-2005, 04:26 AM   #2
320mb
Senior Member
 
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
http://www.ss64.com/bash/index.html
 
Old 01-23-2005, 04:27 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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"
 
Old 01-23-2005, 05:33 AM   #4
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL, CentOS, Ubuntu
Posts: 333

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.
 
  


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:48 PM.

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