LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 02-25-2010, 10:35 PM   #1
manjeshjk
LQ Newbie
 
Registered: Dec 2008
Location: Bangalore
Posts: 6

Rep: Reputation: 0
Find and Copy command comdined together


Hi,

I want to find files of a particular tyepe and particular date to be copied into a seperate folder.

How do i do achieve this in a single line using the find and copy command.

Regards,

Manjesh
 
Old 02-25-2010, 10:47 PM   #2
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567

Rep: Reputation: 57
man find
Code:
       -type c
              File is of type c:

              b      block (buffered) special

              c      character (unbuffered) special

              d      directory

              p      named pipe (FIFO)

              f      regular file

              l      symbolic link; this is never true if the -L option or the
                     -follow  option is in effect, unless the symbolic link is
                     broken.  If you want to search for symbolic links when -L
                     is in effect, use -xtype.

              s      socket

              D      door (Solaris)

       -mmin n
              File’s data was last modified n minutes ago.

       -mtime n
              File’s  data was last modified n*24 hours ago.  See the comments
              for -atime to understand how rounding affects the interpretation
              of file modification times.

       -newer file
              File was modified more recently than file.  If file  is  a  sym‐
              bolic  link and the -H option or the -L option is in effect, the
              modification time of the file it points to is always used.

       -newerXY reference
              Compares the timestamp of the current file with reference.   The
              reference  argument  is  normally the name of a file (and one of
              its timestamps is used for the comparison) but it may also be  a
              string  describing  an  absolute time.  X and Y are placeholders
              for other letters, and these letters select which time belonging
              to how reference is used for the comparison.

              a   The access time of the file reference
              B   The birth time of the file reference
              c   The inode status change time of reference
              m   The modification time of the file reference
              t   reference is interpreted directly as a time

              Some  combinations are invalid; for example, it is invalid for X
              to be t.  Some combinations are not implemented on all  systems;
              for example B is not supported on all systems.  If an invalid or
              unsupported combination  of  XY  is  specified,  a  fatal  error
              results.   Time  specifications are interpreted as for the argu‐
              ment to the -d option of GNU date.  If you try to use the  birth
              time  of  a  reference file, and the birth time cannot be deter‐
              mined, a fatal error message results.  If  you  specify  a  test
              which  refers  to  the  birth time of files being examined, this
              test will fail for any files where the birth time is unknown.
 
Old 02-25-2010, 10:52 PM   #3
manjeshjk
LQ Newbie
 
Registered: Dec 2008
Location: Bangalore
Posts: 6

Original Poster
Rep: Reputation: 0
I need an Example

Hi,

I would understand better if there are some examples

Suppose i want to find files in the cuurent directory and search for files that starts with 5W* and the file date must be 23-Feb-2010 and then i want it to be copied to /mes/data.

Regards,

Manjesh
 
Old 02-25-2010, 10:54 PM   #4
mattca
Member
 
Registered: Jan 2009
Distribution: Slackware 14.1
Posts: 333

Rep: Reputation: 56
Something like this should work:

Code:
cp `find -type <type> <time option> <time> location_to_search_in` destination_dir/
where <time option> is one of: -amin, -atime, -cmin, -ctime, -mmin, and -mtime. See the man page for more info.
 
Old 02-25-2010, 11:18 PM   #5
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
Hi mattca,

Does this work ?

Quote:
Originally Posted by mattca View Post
Something like this should work:

Code:
cp `find -type <type> <time option> <time> location_to_search_in` destination_dir/
Hope location_to_search_in should come immediately after find.

@manjeshjk
You may try this,

Code:
cp `find . -type f <time option> <time> -name "^5W*"` destination_dir.
Your time option is not clear, which time are you talking about access/modification/cretation time?

Last edited by vinaytp; 02-25-2010 at 11:29 PM.
 
Old 02-26-2010, 12:01 AM   #6
mattca
Member
 
Registered: Jan 2009
Distribution: Slackware 14.1
Posts: 333

Rep: Reputation: 56
Quote:
Originally Posted by vinaytp View Post
Hi mattca,

Does this work ?



Hope location_to_search_in should come immediately after find.
Ahh, yeah you are right. The path comes first.
 
Old 02-26-2010, 12:51 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
For a very large number of files, you could use xargs. It also helps when filenames might contain spaces or other white space.

find /path/to/directory/ -iname "*.jpg" -print0 | xargs -0 cp --target-directory=/path/to/target/dir/

The -print0 / -0 options use nulls to separate file name arguments. There are three options of xargs if you need to limit the length of the argument list. see man xargs if this is what you need to do.
 
Old 02-26-2010, 01:47 AM   #8
manjeshjk
LQ Newbie
 
Registered: Dec 2008
Location: Bangalore
Posts: 6

Original Poster
Rep: Reputation: 0
Last modified date

Hi,

In respect to your reply i want there the last modified included in it.

Regards,

Manjesh
 
Old 02-26-2010, 05:27 AM   #9
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
See man find => add -mtime option to find-command to search on last modified date of file, perhaps also -daystart.
See also worm5252's post for other options.
 
  


Reply



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
how to copy drive using dd and tee command parallely? source code of dd command mdfakkeer Linux - Software 1 02-10-2010 01:31 PM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
How to find files and copy the found files to the floppy in one command justmehere Linux - Newbie 11 05-04-2008 11:29 PM
Using the find command with a pipe to copy dbrmik Linux - Newbie 3 06-18-2007 05:08 AM
copy with find ovince Programming 1 03-21-2007 10:46 AM

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

All times are GMT -5. The time now is 03:47 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