Moving files

I wrote a script which moves files on first in first out basis.

for i in `ls -ltr | grep ^- | head -10 | awk '{print $9}'`
do
mv $i Test/
done

But donno some reason, this is not working on my Linux box. May i know the reason?

Can the above script be done by using positional parameters?

for i in $*
do
cd $1
x = `ls -ltr | grep ^- | head -10 | awk '{print $9}'`
mv $x $2
done

please correct me.

You have used a wrong hyphen (minus sign) in your ls command:

ls -ltr | grep ^- | head -10 | awk '{print $9}'

Regards

That will break your script if any filenames contain spaces.

ls -tr | head 10 |
while IFS= read -r i

That will break your script if any filenames contain spaces.

mv "$i" Test/

That doesn't use the positional parameters. That uses filename expansion (wildcards), which would be good if you didn't need to sort them by moditication time.

There must be no spaces around the equals sign.

Calling four external commands for every file is incredibly inefficient, especially since you are doing exactly the same thing every time.