really thx
the playlist is not a good choice beacuse the destination folder is a sd card (/media/Scheda_sd) used in another device
for the space problem i can rename all the files, no prob at all
using an sd memory, perhaps is better to control the freespace instead the folder dimension
and i have a little error during the execution : grep -P option not available (i think that is a good translation of the error)
using this:
Code:
#!/bin/bash
## let's set some variables:
## This is our SOURCE directory
DIR="/media/Hd_Backup/Mp3"
## This is our DESTINATION direction
DIRTOO="/media/Scheda_sd/mp3"
## A temporary file to keep our numbered list
TMPFILE="/tmp/randommp3"
## The max size of the resulting directory
## (give or take the size of one mp3)
THRESHOLD="100000"
## The amount of space CURRENTLY used
## in the destination directory
SPACE=$(du -s "$DIRTOO"|awk '{print $1}')
## The number of files that we're working with
FILENUM=$(ls "$DIR"| grep -c 'mp3')
## This generates our numbered list and stores
## it in the tmpfile
find "$DIR" -name '*.mp3'|cat -n > "$TMPFILE"
## this starts a loop which ends when our threshold
## ($THRESHOLD) is reached
until [ "$SPACE" -gt "$THRESHOLD" ]; do
## This generates our random number based on
## the number of files in the source dir.
RN="$((RANDOM%${FILENUM}+1))"
## This cuts out the file name that corresponds to the
## random number
MP3="$(grep -P "^\s*$RN\t" "$TMPFILE" | awk '{print $2}')"
## Here we do the actual copy
cp -v "$MP3" "$DIRTOO"
## Here we check to see how much space we are using
## before we start the loop again
SPACE="$(du -s "$DIRTOO"|awk '{print $1}')"
## End of the loop!
done
in the meantime, i study the script for try to understand it