LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find iregex (https://www.linuxquestions.org/questions/linux-newbie-8/find-iregex-344310/)

bsg 07-18-2005 11:44 AM

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.

druuna 07-18-2005 11:52 AM

Hi,

These three: ( ) and | are special:

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

Tested the above, so it should work.

bsg 07-18-2005 11:55 AM

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. :o

bsg 07-18-2005 11:07 PM

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]


All times are GMT -5. The time now is 08:34 PM.