copy random files to another directory

Sometimes (probably not that often), you want to copy a sample of files to another directory. For example, copy random mp3s of your collection to a flash drive for your car.

find /directoryWithMyFiles -print0 | shuf -z | xargs -0 cp -t /newDirectoryWithASampleOfFiles/

you could add -n100 to shuf to strip the sample down to 100 items. Otherwise, it will just copy your files as long as there is space left on the device containing the destination directory.

btw: works fine with spaces in file names or german umlauts.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert