The following script does the job:
#!/bin/bash
counter=0
for file in *
do
# Do not delete the script itslef
if [[ "$(basename -- "$0")" == "$file" ]]; then
echo "\$file is the filename of the current script."
continue
fi
((counter++))
if (( $counter % 2 == 0 ))
then
rm "$file"
fi
done
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-04-24 22:08:53 +0000
Seen: 3 times
Last updated: Apr 25
How can I print all but the first 1000 Lines from a File in Bash?
Bash Script that checks if a Host is available or not?
How can I check the expiry of a SSL certificate in the Command Line?
How can I only get the Column with the Filename from a ls -all output with Awk?
What is the Difference of "source script.sh" and "./script.sh" in Bash?
How can I fix error: Security violation, ping RPC from uid 1001 in Slurm log?
I want to grep for "```*" in a File, in other Words: "```" followed by any Word
Sed: I want to remove a Word after all ``` in the given File