I have a directory with a few dozens of files. I would like to do something with every second file from this directory. By now I only used find
command but with thi
I had every file twice, and needed to delete every second file. Find just returned me random files, therefore I added a sort. It now looks like this:
#!/bin/bash
DIRNAME=""
for file in `find $DIRNAME -type f | sort | awk 'NR % 2 == 0'`; do
echo "going to modify" $file
# ls -laFh $file # show file details
# rm $file # delete file
# mv $file # move file to
done
put this in a file called scriptName, run
chmod +x scriptName
and start it by calling
./scriptName