Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to have SCP filter the files that it copies by date, e.g., if you wanted to copy all files that were created on 12/29 and ignore the others?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can't do this directly with scp. The unix way is to combine tools, you want the find command.

Here is an example of searching for a file with a given date:

touch --date "2007-01-01" start
touch --date "2008-01-01" end
find -type f -newer start -not -newer end

I took this example from here: http://www.cyberciti.biz/faq/linux-unix-osxfind-files-by-date/

To feed this into scp you could do this:

find -type f -newer start -not -newer end -exec scp {} dest: \;

This will call scp once per file, which could be slow because it needs to bring up the connection each time. If you only have a handful of files and there are no spaces in the names you can do this:

scp `find -type f -newer start -not -newer end` dest:
share|improve this answer
    
It's easy when you copy files from client to server, but what about the other way around? –  Petr Peller Mar 30 at 18:14
1  
@PetrPeller To copy in the opposite direction you can do this: scp dest:`ssh dest find -type f -newer start -not -newer end` . –  Edward Betts Mar 31 at 11:11
    
Nice trick, thanks ;) –  Petr Peller Mar 31 at 12:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.