Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Linux Commands»How to Find all Files Containing a String in Linux

    How to Find all Files Containing a String in Linux

    By RahulMarch 18, 20171 Min Read

    How to Find all Files Containing a String in Linux. This tutorial will help you to search all files containing specific text string recursively. This tutorial uses “find” command to search string in files. Alternatively, You can also use grep command to search text.

    Command:-


    # find / -exec grep -l “string-to-search” {} ;


    Uses:

    Below is an example command which searches text ‘redhat’ in / filesystem. This command will search for all files containing string ‘redhat’ and list file names only like below.

    # find / -exec grep -l "redhat" {} ; 
    
    /lib64/security/pam_oddjob_mkhomedir.so
    /lib64/libdevmapper.a.1.02
    /lib64/libdevmapper-event.a.1.02
    /lib64/libdevmapper.a
    /lib64/libdevmapper-event.a
    ...
    

    To Search in specific file extension files. Like search ‘redhat’ in all php files only, use following command.

    # find / -name '*.php' -exec grep -l "redhat" {} ; 
    
    /var/www/projects/index.php
    /var/www/projects/new.php
    ...
    

    files find search
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Ignore SSL Certificate Check with Wget

    How to Ignore SSL Certificate Check with Curl

    echo Command in Linux with Practical Examples

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Using .env Files in Django
    • Using .env File in FastAPI
    • Setting Up Email Notifications for Django Error Reporting
    • How to Enable Apache Rewrite (mod_rewrite) Module
    • What are Microservices?
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.