List matching directories in current folder only on AIX

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support List matching directories in current folder only on AIX
# 1  
Old 02-24-2012
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.
# 2  
Old 02-24-2012
I don't have an AIX, but I'm guessing this would work (may be with few minor tweaks)
Code:
ls -l | grep "^d" | awk '{print $NF}'

# 3  
Old 02-24-2012
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
# 4  
Old 02-24-2012
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?
Code:
ls -l | egrep "^d.*[0-9]{9}" | awk '{print $NF}'

# 5  
Old 02-24-2012
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..
# 6  
Old 02-24-2012
I hope you have Perl on your system.
Code:
#! /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).

Last edited by balajesuri; 02-24-2012 at 04:10 AM..
# 7  
Old 02-24-2012
first check whether you are getting the correct directory name or not

Code:
 
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"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

List all files and directories in the current directory separated by commas and sorted by crtime

What I know so far: ls -A will list all files except those starting with a dot ls -d will list all directories ls -m will separate contents by commas For getting crtimes use: stat filename will give me the inode number or ls -i filename will give... (13 Replies)
Discussion started by: chstewar
13 Replies

2. UNIX for Dummies Questions & Answers

List the directories, having given pattern in the directories name, sorted by creation date

It is for HP-Unix B.11.31. Requirement: 1. List the directories, having given pattern in the directories name, sorted by creation date. Example: Directories with name "pkg32*" or "pkg33*" 2. On the output of 1. list the directories by creation date as sort order, with creation date... (2 Replies)
Discussion started by: Siva SQL
2 Replies

3. Shell Programming and Scripting

Find specific files only in current directory...not sub directories AIX

Hi, I have to find specific files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help.. I am using the below command. And i am... (2 Replies)
Discussion started by: aakishore
2 Replies

4. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

5. Shell Programming and Scripting

How to list Matching Directories OR NULL w/o error message?

I want to be able to get all the directories in a path into a variable array, BUT if there ARE NO directories I want the Variable to be NULL and not echo any error message! If there ARE directories, this will get the list of the directories whose name begins with the string "20":... (6 Replies)
Discussion started by: pgorbas
6 Replies

6. UNIX for Dummies Questions & Answers

tar file from current folder

Hello guys, I am sure this has been asked before, but honestly, I cant find post talking about it. Here is what I need: - A tar file will be generated manually by user - This tar file is then used within a bash shell script My source folder structure is like this: ... (2 Replies)
Discussion started by: manolain
2 Replies

7. Shell Programming and Scripting

How to list all the directories, sub directories in a mount along with size in ascending order?

Hi , I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In a particular mount, have to list all the directories and sub directories along with size of the directory and sub directory in ascending order. Please help me in this regard and many... (4 Replies)
Discussion started by: nmakkena
4 Replies

8. UNIX for Dummies Questions & Answers

List files that are not directories from current directory

I can't manage to list all files that are not directories from current directory. (2 Replies)
Discussion started by: beni22sof
2 Replies

9. Shell Programming and Scripting

How to find files in current folder only?

How do I find files in current folder only? We are on AIX 5.3, so maxdepth is not supported. I tried to do this find /dir1/dir2/dir3/dir4 -prune -type f to display all files in /dir1/dir2/dir3/dir4 only but it does not show any files. Somehow the -prune option works for dir3 level... (7 Replies)
Discussion started by: Hangman2
7 Replies

10. UNIX for Dummies Questions & Answers

Pack current folder

How do I pack (using tar zcvf ?) the current folder inluding all files and folders ?? I need to be sure to get all files and folders/subfolders... Later I will unpack into a new folder on a new server.. Appreciate any help.. (3 Replies)
Discussion started by: WebWatch
3 Replies
Login or Register to Ask a Question