moving the first N files from a folder script Bash

sometimes you find yourself in the position were you want to gradually move files from one location to another (to be processed for instance) you don’t to move the files all at once and you don’t have a certain criteria to limit your find command with. I’d have expected find to have an argument that’d would control the number of files returned but it doesn’t instead you have to use a counter and for loop to force the script to exit after moving certain number of files.

I’ve written a rather simple script to do that and here it is, I’m sure there is a more elegant way to do this however I wrote this as a quick and dirty fix.


for file in `ls -t`
mv $file tempdir;

if [ “$i” -eq  6 ]
exit 0;



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s