0

I want to move my older files in another directory with a script like this

find /sourcedirectory -maxdepth 1 -atime +700 -type f -exec mv "{}" /destination/directory/ \;

That works well, but it´s not sorted like before. So I am looking for a way to mirror the folders and sort the files in them like before.

Is that possible?

  • 1
    What do you mean, "it's not sorted"? – roaima Oct 16 '18 at 6:31
  • currently there are many folders with files in it and if I use that script all my unused files are in one folder. I hope you can understand that my english is not the best – NikSch Oct 16 '18 at 6:34
  • 3
    Possible duplicate of How to move files that have a last access time 2 years ago – Henrik Oct 16 '18 at 6:45
  • One option might be to have find construct the list of files to be moved, then call on rsync to do the 'heavy lifting' and make sure the directory structure is mirrored correctly. – Shadur Oct 17 '18 at 6:41
  • @henrik Not a dupe - the answer to the linked question is the stepping-off point to this question. Related, but not a duplicate. – Shadur Oct 17 '18 at 6:42
0

If you would like to rsync only the filers younger than 31 days from your source folder, you can combine rsync and find in this way:

rsync -Ravh $(find /path/to/folder/ -type f -mtime -31)  /path/to/destination/folder
0

I can't test this right now but try

find /sourcedirectory/./ -maxdepth 1 -mtime +700 -print0 |
    rsync -a --files-from=- --from0 --remove-source-files / /destination/directory/

Actually, since you've specified -maxdepth 1 no subdirectories will be considered, so there is no need for anything other than the command you stated in your question:

find /sourcedirectory -maxdepth 1 -atime +700 -type f -exec mv "{}" /destination/directory/ \;

This makes it a duplicate of your earlier question.

  • Is it maybe possible without rsync? – NikSch Oct 16 '18 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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