Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

ls - searching subdirectories

  • 07-03-2007 01:55PM
    #1
    Registered Users, Registered Users 2 Posts: 801 ✭✭✭


    This is probably a dumb ass question but here goes...

    I know that ls -R lists all files in all subdirectories recursively, but how do I search for a file in all subdirs?

    so for example, if I want to search for *.c files in the current dir and all subdirs, how do I do it using ls (dir /s *.c in DOS)?


Comments

  • Registered Users, Registered Users 2 Posts: 391 ✭✭Dopey


    find . -name \*.c


  • Registered Users, Registered Users 2 Posts: 801 ✭✭✭Nature Boy


    Cool thanks.

    That exact command didn't work but find -name *.c does...


  • Registered Users, Registered Users 2 Posts: 273 ✭✭electrofelix


    Nature Boy wrote:
    Cool thanks.

    That exact command didn't work but find -name *.c does...

    Dopey was probably trying to avoid shell expansion. If you have a file called file.c in the current directory that command you used will end up searching all the sub dirs for file.c not *.c

    better way to make sure you get what you want

    find . -name '*.c'

    Prevents shell expansion.

    Also you may find that
    find . -type f -name '*.c'

    is significantly faster if there are a lot of directories and you only want a file. Because it will skip matching any directory names with the name pattern.


Advertisement