Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, 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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2010
    Posts
    2

    Copy Directories based on Modified Date


    Hi,

    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.

    /webmain/tmb/June-2010

    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!

    Darthvader

  2. #2
    Just Joined!
    Join Date
    Aug 2010
    Posts
    18
    Code:
    folder=/webmain/tmb/$( date +%B-%Y )
    mkdir $folder
    
    for file in $( find /directory_path -mtime -30 -print) ; do cp $file $folder ;done

  3. #3
    Just Joined!
    Join Date
    Sep 2010
    Posts
    2
    Barbus,

    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
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Aug 2010
    Posts
    18
    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
  •