Is it possible to write a script to select every second file

I found something similar


but it's been taken off line.

I create numerous routine backups, after a while it's no use keeping all of them, halving them by selecting every second one would be useful.

Using Nautilus 3.4 the one from Ubuntu 12.04.


Perhaps it would be wiser to move the files to a Trash folder rather than to delete them altogether.You can achieve this by selecting script from nautilus context menu. I can't tell what script you are referring to, but this one will do just fine.

So, create the script, make it executable and place it in the nautilus script folder.

files_del=$(echo "$comm_susbst" | sed -n 'n;p')
num_files=$(echo "$files_del" | wc -l)
zenity --question --title="Delete every second file" \
--text="Are you sure you want to delete these files? \n You will delete $num_files files! \n\n $files_del"
    if [ $? == 0 ]; then
        echo "$files_del" | while read; do mv -t /home/$USER/.local/share/Trash/files "$REPLY"; sleep 0.1; done
    else exit 1
exit 0

After selecting files and running a script zenity window will pop-up for confirmation.If you insist on deleting files than replace the mv line with do rm -f "$REPLY". I hope it works as you imagine it will :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.