Copy files matching multiple conditions

Hello

How do i copy files matching multiple conditions. Requirement is to search files starting with name abc* and def* and created on a particular date or date range given by the user and copy it to the destination folder.

i tried with different commands.

below one will give the list , but don't know how to copy.

ls -l | grep -e "abc" -e "def" |grep -i "May 21"

below one copies on one condition, don't know how to insert multiple condition

find -iname "abc*" -exec cp -i -t ~/test {} + 

Have you considered something like:-

grep -i "May 21" *abc* *def*

The output will list the filenames found followed by the matching record. Have a look at the -h & -l flags of grep if you want to exclude wither of these.

I hope that this helps.

Robin
Liverpool/Blackburn
UK

You can specify an OR in the find conditions - find \( -name "abc*" -o -iname "def*" \) -exec stuff... .

Thanks Carol

but it throwing me error

Usage: find [-H | -L] Path-list [Expression-list]

Must be a user error, my name's not Carol! :slight_smile:

What's your OS? If it's SunOS/Solaris then try /usr/xpg4/bin/find .

EDIT: Actually, it's probably just the Path-List that was missing from your original command. Try:

 find . \( -iname "abc*" -o -iname "def*" \) -exec cp -i -t ~/test {} \;

The first parameter of find is a directory name. It can be a dot for the current directory or should be a forward slash for directory names not the backslash and for a simple or list you can drop the brackets.

Try:-

find / -name "abc*" -o -iname "def*" -exec stuff....

Robin