Got a directory with > 10K of files? Need to move them up one directory? mv will fail you:
$ mv * .. -bash: /bin/mv: Argument list too long
The solution is to list the files one line at a time (with find or ls -1) and feed that to xargs:
ls -1 | head -100 | xargs -I f mv f ..
This moves the first 100 files up one directory.
Note that this won’t work if you’ve got whitespace in your filenames. Use find -0 and xargs -0 to null-separate your filenames in that case.
Related posts:
- Running a command for all files whose name matches…
I found a stray image named “img_1234.jpg” on a laptop and wanted to see if I already had it on my server. On my Mac I could use spotlight’s nifty...... - Recursive sort-by-modification-time
This certainly isn’t rocket science, but it also is certainly not something you want to type more than once. find . -type f -printf '%T@\t%p\n' | sort -n | cut......