Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Completely overengineered compared to a bash one liner using find + xargs, but here is a quick python script, partly mashed up from some other scripts I had written before. Should work quite well for your purposes.</p> <p>Now the only reason I went to the effort is because of that comment you made: </p> <blockquote> <p>Yes, I could spend month+ learning one of those languages</p> </blockquote> <p>Its well worth the effort, and will pay itself off very quickly. This script took about 7 minutes including doing some tests. </p> <pre><code>#!/usr/bin/python import datetime import os import sys import shutil SOURCE_PATH = "/home/customers/" TARGET_PATH = "/home/oldcustomers/" TIME_THRESHOLD = datetime.timedelta(365) #days def get_old_dirs(source_path, time_threshold): old_dirs = [] for root, dirs, files in os.walk(source_path): for d in dirs: full_path = os.path.join(root, d) now = datetime.datetime.now() last_modified = datetime.datetime.fromtimestamp(os.stat(full_path).st_mtime) delta = now - last_modified if (delta) &gt;= time_threshold: old_dirs.append((full_path, delta)) break return old_dirs def move_old_dirs(target_path, source_path, time_threshold, confirm=True): dirs = get_old_dirs(source_path, time_threshold) print '"old" dirs: %d' % len(dirs) if dirs: if confirm: print "pending moves:" for (d, delta) in dirs: print "[%s days] %s" % (str(delta.days).rjust(4), d) if not raw_input("Move %d directories to %s ? [y/n]: " % (len(dirs), target_path)).lower() in ['y', 'yes']: return if not os.path.exists(target_path): os.makedirs(target_path) for (d, delta) in dirs: shutil.move(d, target_path) print "%s -&gt; %s" % (d, target_path) print "moved %d directories" % len(dirs) def cmdline(args): from optparse import OptionParser usage = "move_old_dirs [options] &lt;source_dir&gt; &lt;target_dir&gt;" default_desc = "%s -&gt; %s [%s]" % (SOURCE_PATH, TARGET_PATH, TIME_THRESHOLD) parser = OptionParser(usage) parser.add_option("-d", "--days", action="store", type="int", dest="days", default=365, help="How many days old the directory must be to move") parser.add_option("--default", default=False, action="store_true", dest="default", help="Run the default values set in the script: (%s)" % default_desc) parser.add_option("-f", "--force", default=False, action="store_true", dest="force", help="Dont ask for confirmation") (options, args) = parser.parse_args(args) if len(args) == 1 and options.default: print "running default: %s" % default_desc return move_old_dirs(TARGET_PATH, SOURCE_PATH, TIME_THRESHOLD, confirm=(not options.force)) elif len(args) == 3: return move_old_dirs(args[2], args[1], datetime.timedelta(options.days), confirm=(not options.force)) print usage print "incorrect number of arguments, try -h or --help" return 1 if __name__ == "__main__": cmdline(sys.argv) </code></pre> <p>just chuck that in some file (like <code>move_old_dirs</code>) in PATH, chmod to executable and have a go.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload