AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
Expand all | Collapse all

AIX FIND COMMAND

  • 1.  AIX FIND COMMAND

    Posted Fri December 27, 2013 05:50 AM

    Originally posted by: s_m_gopinath


    Hi Guys, 

    I am trying to use the find command on AIX 6.1.0.0 to find only files in main directory without recursive search to the directories inside that. The below is the find command that I used, but its doing the recursive search how to stop that find command from doing recursive. 

    find . -name '1_EVT*' -prune -exec ls -lrt {} \; 

    Let me know how to use the find command to find only files without going into sub directories. 

    With regards, 
    Gopinath.



  • 2.  Re: AIX FIND COMMAND

    Posted Fri December 27, 2013 06:57 AM

    Originally posted by: LaurentOliva


    The prune option works as follow :

    You need to explicity specify the directory to exclude.

     

    For example :

    $ find . -name .ssh
    ./.ssh
    ./foo/bar/.ssh

    $ find . \( -name foo -prune \) -o \( -name .ssh -print \)
    ./.ssh
     

    You can also use wildcards :

    $ find . \( -name fo* -prune \) -o \( -name .ssh -print \)
    ./.ssh

    Filtering by directories in order not to exclude file searching :

    $ find . \( -type d -name fo* -prune \) -o \( -name .ssh -print \)
    ./.ssh

     


     

     

     



  • 3.  Find | Specifying Directory Level

    Posted Wed January 01, 2014 12:53 AM

    Originally posted by: vbalaji11


    Hi Gopinath,

     

    As daboule suggested, you can filter using prune. Refer the link here
     

    and also it will be simple to use maxdepth & mindepth. Click here

    " find / -name "filename" -maxdepth 1 "

    will serve the purpose.

     



  • 4.  Re: Find | Specifying Directory Level

    Posted Fri January 03, 2014 04:29 AM

    Originally posted by: LaurentOliva


    vbalaji11

     

    The maxdepth option you described is only available on the GNU version of the find command, which is delivered on Linux boxes.

    On AIX, this not the case at all.

    If you want to use the GNU version of the find command on AIX, you must install it from 

    AIX Toolbox for Linux Applications

     

     



  • 5.  Re: AIX FIND COMMAND

    Posted Mon August 18, 2014 11:54 PM

    Originally posted by: kkwoo


    Hi Gopinath,

        Elsewhere on the internet <<http://unix.ittoolbox.com/groups/technical-functional/shellscript-l/nonrecursive-option-for-find-command-1416198>>, I found an invocation of 'find' which will do what we want using AIX's find:

    find . ! -name . -name '1_EVT*' -prune -exec ls -lrt {} \;

        The main difference is adding the "! -name ." clause.

    Regards,

    Kevin

     



  • 6.  Re: AIX FIND COMMAND

    Posted Wed August 20, 2014 09:47 AM

    Originally posted by: YannickBergeron


    You could write a really short perl script that make use of the glob() subroutine

     

    ex:
    #!/usr/bin/perl

    use strict;

    use File::Basename;

    for my $file (glob('/yourdir/*')) {

      next() if (basename($file) !~ m/^1_EVT/);

      # other logic

      print $file . "\n";

    }

     

     

    it could also probably be simplified to be a perl 1 liner which would be less readable by common human species ;)