I want to create a script to delete any directories with numeric groups.
What I have so far captures and analyzes the group:
#!/bin/bash re='^[0-9]+$' for x in `/usr/bin/ls -l /var/indexes | sort -k3,3 | tr -s " " | cut -f3 -d " "` do if [[ $x =~ $re ]] ; then echo "found one $x" fi done
The problem is, the actual name of the directory is in another column.
Here is one line of the ls output:
drwxr-sr-x. 3 3966 root 4096 Oct 20 16:29 dirname
So I need to iterate through the ls results and capture both the group (in this case 3966) and the directory name (in this case dirname) so I can form an rm -rf command to remove it when I find a blank one.
How would I do that?
Thanks in advance.