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

searching for a file in unix ..

  • 13-05-2008 12: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,088 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,043 ✭✭✭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,563 ✭✭✭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: 35,731 Mod ✭✭✭✭pickarooney


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


Advertisement