Friday, April 19, 2019

command line - How to search for files containing specific word?


How to search for files containing specific word?



With command line you have several options. The 3 I use the most are...



  1. locate {part_of_word}


    This assumes your locate-database is up to date but you can update this manually with: sudo updatedb


  2. grep as explained by dr_willis.
    One remark: -R after grep also searched within directories.
    Example:


    cd\
    grep -R {something_to_look_for} {where_to_look_in}

  3. find . -name '*{part_of_word}*' -print



Where . is the directory where you are at the moment and * is a wildcard.


Oh and you can also combine these. Example:
locate {something}|grep {some_part_of_something}|more


If I recall correctly: locate is the fastest one (assuming your database is up to date) and find is the slowest one. And grep is the most complex but also the most versatile one of these since you can use regexes.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...