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 07-18-2005, 12:44 PM   #1
bsg
LQ Newbie
 
Registered: Jul 2005
Posts: 7

Rep: Reputation: 0
find iregex


I'm trying to put together a shell script (one liner) that will backup the contents of a specified directory into a gzipped tarball. I'm trying to filter out what I want backed up with find's iregexp option but I'm stuck. Does the -iregexp treat parenthesis as metacharacters because I'm not getting the results I want?

Here is the script I'm using. Problem is with the (), they don't seem to be treated as the proper regular expression because nothing is returned.
Code:
find media/ -iregex '.*\.(jpg|jpeg)'
Anybody have any ideas on how I can do this?

The final script should look something like this
Code:
find media/ -iregex '.*\.(jpg|jpeg)' | xargs tar -cvzf backup.tar.gz
PS. If you're wondering what I'll be using this for, its for a php script. I don't run a linux box at home.
 
Old 07-18-2005, 12:52 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

These three: ( ) and | are special:

find media/ -iregex '.*\.\(jpg\|jpeg\)'

Tested the above, so it should work.
 
Old 07-18-2005, 12:55 PM   #3
bsg
LQ Newbie
 
Registered: Jul 2005
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by druuna
Hi,

These three: ( ) and | are special:

find media/ -iregex '.*\.\(jpg\|jpeg\)'

Tested the above, so it should work.
Thanks, you're so right.
 
Old 07-19-2005, 12:07 AM   #4
bsg
LQ Newbie
 
Registered: Jul 2005
Posts: 7

Original Poster
Rep: Reputation: 0
EDIT: Nevermind, ayecee helped me on irc. He recommended that I use print0 along with xargs -0 to achieve what I wanted.

[s]If I were to use these as arguments for another shell cmd, you wouldn't happen to know how to put each line in quotes so the cmd won't break if the files or directorys have spaces in them.[/s]

Last edited by bsg; 07-19-2005 at 01:17 AM.
 
  


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
linux find to find files with multiple patterns subu_s Programming 6 12-15-2010 01:15 AM
Can`t find C-compiler in Debian ,or at least can`t find one that can make executables hemmelig Linux - Software 4 05-26-2008 04:07 AM
I can find the camera but can't find the images? sneckert Linux - Newbie 2 02-02-2005 09:51 AM
find: . changed during execution of find suse degraffenried13 Linux - General 3 12-12-2004 08:13 PM
linux 'find' to find text files subu_s Programming 2 12-02-2004 03:56 AM


All times are GMT -5. The time now is 05:23 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration