Results 1 to 3 of 3

Thread: Move certain filetypes to different dirs, w cron?

  1. #1
    Join Date
    Jan 2009
    Beans
    2

    Move certain filetypes to different dirs, w cron?

    I've looked around at a few places and thought I'd post here after I've poked around a bit to find my own answer... so here it goes:

    I'd like to set a cron for x number of minutes to poll a directory copy all pictures to a certain dir, mp3's to another and unpack any zip, rar ect files... even as far as ones buried in folders and then delete the whole mess once everything's been moved out of my upload dir.

    I know ubuntu can do it, just not sure how to go about finding the answer out for myself.

    Thanks for reading.

  2. #2
    Join Date
    Dec 2007
    Location
    United States
    Beans
    2,865
    Distro
    Ubuntu

    Re: Move certain filetypes to different dirs, w cron?

    This is possible with shell scripting, but the unzipping process would be advanced. I think it would be about a half day's work to get it setup and debugged, but it would be a great project for you to learn shell scripting.

    For example. To move all MP3's from one directory to another cold be a simple script such as:

    Code:
    #!/bin/bash
    cd /my/directory
    rename 'y/MP /mp./' *
    mv *.mp3 /my/newdirectory
    You could save this as "movefiles.sh"

    Cron can be told to run it via:

    sudo crontab -e

    Then entering a line such as:

    Code:
    0,10,20,30,40,50 *     *     *     *         /path/to/my/movefiles.sh
    This basically means run this every 10 minutes of every hour of every day of the month of every month and on all seven of the days of the week.

    See http://www.adminschoice.com/docs/crontab.htm for more information on the format of the crontab file.

    Be certain to test your scripts before trying to put them into cron and welcome to bash shell scripting! It is a powerful tool.

  3. #3
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Move certain filetypes to different dirs, w cron?

    As stated above, the crontab is really the only confusing part. A slightly shorter way to specifiy your crontab would be:

    Code:
    */10 * * * * command
    That means "every ten minutes".

    The other thing you are going to find useful is find. For example, to find all .zip files even if they are in subdirectories use:

    Code:
    find /path/to/files -type f -name "*.zip"
    The syntax to unzip them once they are found will probably be something like:

    Code:
    find /path/to/files -type f -name "*.zip" -exec unzip {}\;
    Don't try to make something "fast" until you are able to quantify "slow".

Tags for this Thread

Bookmarks

Posting Permissions

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