FOR <condition> do
file=`ls <directory> | tail -1`
echo $file
mv -f $file <another dir>
done
What I want to now is what should I put in the <condition>. The condition I want is that the FOR will execute until there is no more files in the directory
for file in <directory>/*
do
echo $file
mv -f $file <another dir>
done
The is a problem with this for loop : if the directory is empty body of the loop is executed nevertheless with the variable file set to '<directory>/*'
Another solution with the for loop :
for file in `ls -1 <directory>/* 2>/dev/null'
do
echo $file
mv -f $file <another dir>
done
You can also use a while loop :
ls -1 <directory>/* 2>/dev/null | \
while read file
echo $file
mv -f $file <another dir>
done