Project

randfiles

0.0
No commit activity in last 3 years
No release in over 3 years
Given a set of random directories, this scripts outputs the files in them in a random order. Combined with limitations by size or by number, this can be used to pick a random collection of files from the given directories.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
>= 2.0.0
 Project Readme

Overview

This little utility can be used to choose a random selection of files from a given directory and output the list to stdout. The invocation looks like this:

randfiles [options] [dir1, [dir2, [...]]]

If no directories are given, the current directory is used. The possible options are:

  • -s, --size-limit [SIZE]: Set a size limit for the selected files. For example, randfiles --size-limit 400MB will select up to 400MB of files.
  • -c --count [N]: Set the maximum number of files. randfiles --count 3 would only choose three random files.

Examples

To copy a random selection of music to a flash drive, limited to 3GB, you can do this:

randfiles --size-limit 3GB ~/music | xargs -i -d'\n' cp -v {} /mnt/usb

If you're unfamiliar with xargs:

  • -i replaces all occurrences of {} with what's read as input
  • -d'\n' ensures that the items are delimited by newlines (there may be spaces in the file names)

Installation

The project is available as a gem, so this should be enough:

gem install randfiles

Todo

  • A -0 option for easier piping
  • Filtering files by regex or glob