Skip to main content

How to move the first x files [Resolved]

I have this huge folder with thousands of unordered files. Is it feasible to move the first 5000s to a subfolder via the mv command? For now I move files with

 mv *some_pattern* ./subfolder1/

As for now, I move images quite randomly, it's not really important if there aren't exactly 5000 files in each subfolder. Is there a better way to do it?

Question Credit: Fabinout
Question Reference
Asked September 13, 2018
Posted Under: Unix Linux
5 Answers

i will keep it simple: 1) Goto the directory which you want to move files from 2) hit below command

find . -name Hello*.gz |head -5000|xargs -I {} mv {} /data01/path/ &

3) . (dot) denotes current directory

finds files which start with Hello and end with gz , first 5000 files will be moved to the path

credit: Pratik Hiremath
Answered September 13, 2018
Your Answer