Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

ls - searching subdirectories

  • 07-03-2007 12: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