Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Copy Directories based on Modified Date


    I want to be able to copy directories from one location to another.

    Such as /webmain/tmb

    I want to write a script that will copy all the directories(including sub files) from within that folder that were modified within a given month and transfer them to a folder under the tmb folder with the month identifier as the directory name.


    What copy functions should I look at to take care of this? Are there any good examples of starter scripts out there?

    Any advice would be greatly appreciated!


  2. #2
    folder=/webmain/tmb/$( date +%B-%Y )
    mkdir $folder
    for file in $( find /directory_path -mtime -30 -print) ; do cp $file $folder ;done

  3. #3

    Thanks for the reply. Do I need to set this up in a script, or can i execute this directly from ssh?

  4. $spacer_open
  5. #4
    It should work independently of way you use it.
    But I suppose it would be more comfortably to run it as script by cron.
    Also please draw attention that this script finds only files changed for last 30 days and not 31 or 28.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts