mv: argument list too long – processing millions of files


Due to my forgetfulness, a cron job had accumulated more than 3 million files in a directory, which I now wanted to process. So that my script doesn’t work on it for days (more 60 GB of data!), the files should be divided into smaller chunks. Unfortunately, mv couldn’t handle it, it complained with “argument list too long”. The remedy is a combination of command line commands:

find folder1/ -name ‘2017-07*’ -exec mv {} folder2 ;