The following script seems to be a good one but it will work only if you have "well behaving" filenames [1]:
#!/bin/bash
foo=0
for f in $(ls -rt) ; do
if [ $((foo%2)) -eq 0 ];
then
echo "even " "$f"; // maybe here copy
else
echo "odd" "$f" ; // maybe here skip
fi
let foo++
done
So essentially no newlines, no tab, no spaces... as it seems in your case.
Please remember that is not safe to parse the output of ls
[1] and doublecheck always.
If you are not in the safe area in which you can use ls, then you may consider to find a solution with find
, maybe taking some inspiration from Gilles' answer [2].
Ps> In case of data corruption, even in a light case as yours, it always needed to check that the patch worked. Often is more convenient to start again from the beginning. If, as I guess, the data size is huge and you cannot transfer/download it again, it's always possible to do some check (e.g. md5sum
[3]) on the original data and the patched one.
ls -t
"-t sort by modification time, newest first". What do you mean with "copying every other"? PS> Do not parse the output ofls
you can incur in problems.100%
about the data. Which kind of results will you obtain? Note that when you proceed lossy, relying on the sureness that a major failure will warn you if something is not correct... the Murphy's_law will show. If those files are of a different kind (check withfile file1 file2
) you can rely a little more. You can wipe out the doubts withmd5sum
on local and original copy...