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.

searching for a file in unix ..

  • 13-05-2008 01:42PM
    #1
    Closed Accounts Posts: 1,788 ✭✭✭


    how can isearch all directories for a speciifc file in unix ?

    something like ls -al "filename"

    ??


Comments

  • Registered Users, Registered Users 2 Posts: 39 Talon.ie


    The command you're looking for is the 'find' command. Typing 'man find' at the command prompt will show you the correct syntax for what you want to do.


  • Moderators, Science, Health & Environment Moderators Posts: 10,093 Mod ✭✭✭✭marco_polo


    jackdaw wrote: »
    how can isearch all directories for a speciifc file in unix ?

    something like ls -al "filename"

    ??

    find . -name "file"

    If you are getting alot of annoying "cannot read dir /blah/blah Permission denied" errors you can supress them like this.

    find . -name "file" 2>/dev/null


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    This is more of a Unix issue than a programming one. Gentlemen, start your beards :pac:


  • Registered Users, Registered Users 2 Posts: 1,042 ✭✭✭2 Espressi


    How about:

    # cd to root dir

    cd /

    # recursive ls, filter with grep
    ls -laR |grep filename


  • Closed Accounts Posts: 891 ✭✭✭conceited


    Gentlemen, start your beards
    Haha.


  • Advertisement
  • Closed Accounts Posts: 12,807 ✭✭✭✭Orion


    First update the file database:

    'sudo updatedb'

    then

    'locate filename'

    [edit]you can probably scratch all that - I assumed Linux not Unix).


  • Closed Accounts Posts: 7,562 ✭✭✭leeroybrown


    2 Espressi wrote: »
    How about:

    # cd to root dir

    cd /

    # recursive ls, filter with grep
    ls -laR |grep filename
    Slow with a big overhead and a decent chance of false positives. The 'find' command is quicker, more likely to be right and far more powerful.

    An example was already given above:
    find . -name "file"
    

    A more complex example:
    find ~/public_html/ -type d -exec chmod o+x {} \;
    

    This would add world execute permissions to all directories in my public_html directory as required for web access.

    The 'magic' thing about the -exec option to find is that you don't have to worry about spaces and other characters that would break a piped command. It just works.


  • Moderators, Arts Moderators Posts: 36,205 Mod ✭✭✭✭pickarooney


    Google desktop for linux.
    Or slocate, if you want to keep it simple.


Advertisement