List matching directories in current folder only on AIX

Hi,

I need to find the list of matching direcories in current folder only and no subfolders on AIX.I tried -maxdepth option but its not working.

Also, tried ls -d option to list the matching directories but getting argument list too long...

So, any help would be appreciated.

I don't have an AIX, but I'm guessing this would work (may be with few minor tweaks)

ls -l | grep "^d" | awk '{print $NF}'

Balaji,

This will list all the directories, but i need only the matching directories.

I tried to update the command like this:

ls -l [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | grep "^d" | awk '{print $NF}'

but I am getting Arg list too long. Do you know any alternate for maxdepth option in FIND command that is supported on AIX

I don't have any idea when you say "i need only the matching directories". Please elaborate.

Analysing your attempt in post #3, are you looking for something like this?

ls -l | egrep "^d.*[0-9]{9}" | awk '{print $NF}'

ok...

give me a command which searches for files only in the current directory and no sub directories and deletes them at the same time.

Also, please consider the point that the file list is too long so if you just try to do it with ls command or rm command to list the matching file , you will be getting Argument list too long error message.

Hope it sounds clear now..

I hope you have Perl on your system.

#! /usr/bin/perl -w
use strict;
use File::Path;

opendir DH, "/home/user";
for $f (readdir (DH)) {
    if (-d $_ && /^\d{9}$/) {
        print "Deleting dir $_\n";
        rmtree $_;
    }
}
closedir DH;

Caution: The above program will search in "/home/user" for all directories with name as a 9 digit number and remove it (regardless of whether it is empty or not).

first check whether you are getting the correct directory name or not

 
for i in $(ls -l | grep "^d.*[0-9]\{9\}$" | awk '{print $9}'); do echo $i; done

then rename the echo command with "rm -rf"