Zipping files by numeric name range

Hi there,

Not being too up on bash shell programming at this point, could anyone throw me a bone about how to zip up a set of numerically-named files by range?

For example, in a folder that contains files 1.pdf through 132000.pdf, I'd like to zip up just those files that are 50000.pdf and greater.

Many thanks!
Tim

Create a bash script like this ...


mkdir destination

for x in /yourfolder/{5000..1000000}; 
do cp  $x destination; 
done;

zip destination;

Hope this helps ...

Much appreciated, Steve!

I only had to add my file extension:

mkdir destination

for x in /yourfolder/{5000..1000000}.pdf;
do cp  $x destination;
done;

zip destination;

Thanks for the leg up.

Tim

HI Tim,

Yes, I forgot the file extension ...

The 1000000 simply represents an upper maximum value.

Does the script actually work ?

Steven M

Yes, Steve, it does the job I needed, allowing me to pull specific ranges of files.

It also has the added benefit of reporting which files in the range are missing, because it will complain when one is missing:

cp: cannot stat `instruments/132479.pdf': No such file or directory
cp: cannot stat `instruments/132480.pdf': No such file or directory
cp: cannot stat `instruments/132481.pdf': No such file or directory
cp: cannot stat `instruments/132482.pdf': No such file or directory
cp: cannot stat `instruments/132483.pdf': No such file or directory

This has also been very helpful to know.

I really appreciate your time,
Tim

You could try this ....

mkdir destination

for x in /yourfolder/{5000..1000000}*.pdf;

if ! test -e "$x"
   then
   echo "$x" does not exist
   continue;
fi

do cp  $x destination;
done;

zip destination;

It's best to always redirect diagnostic messages to stderr, so that when someone runs your script with stderr redirected, the messages are sent to the correct destination.

echo error_message 1>&2

Regards,
Alister