LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find and Copy command comdined together (https://www.linuxquestions.org/questions/linux-newbie-8/find-and-copy-command-comdined-together-791636/)

manjeshjk 02-25-2010 10:35 PM

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

worm5252 02-25-2010 10:47 PM

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.


manjeshjk 02-25-2010 10:52 PM

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

mattca 02-25-2010 10:54 PM

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.

vinaytp 02-25-2010 11:18 PM

Hi mattca,

Does this work ?

Quote:

Originally Posted by mattca (Post 3877247)
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?

mattca 02-26-2010 12:01 AM

Quote:

Originally Posted by vinaytp (Post 3877271)
Hi mattca,

Does this work ?



Hope location_to_search_in should come immediately after find.

Ahh, yeah you are right. The path comes first.

jschiwal 02-26-2010 12:51 AM

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.

manjeshjk 02-26-2010 01:47 AM

Last modified date
 
Hi,

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

Regards,

Manjesh

timmeke 02-26-2010 05:27 AM

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.


All times are GMT -5. The time now is 09:24 PM.