How to Search for Files and Folders Recursively via SSH

You need to use the following command to search for a file called FileName.txt under the current folder including all subfolders

  1. find ./ -type f -exec grep -l "text to find" {} \;

find . -name FileName.txt

If you are unclear about the file name or want to match a part of the file name, you can use a wildcard pattern:

find . -name “FileName*”

To Search only directories excluding all files:

find . -type d

If you would like to filter only files modified for the last 4 days, you can use:

find . -mtime -4

Searching word or textual content in folder, file or directory with its sub-folders you can use ‘grep’ command for the same.
E.g. want to find word “Images”

grep “Images” configuration.php

If you don’t know which file contains the text, you can use:

grep -r -l “Images” *

================================
-r = It will look recursively.
-H = It will gives the result in human readable format.

-l = only file name
“Images” * = For the string “Images” in all (*) files under the current folder.
================================

To only list the file names comprising the string you’re looking but leave out the line containing it, you can use the -l command:

grep -l “Images” *

 5,620 total views,  9 views today

Comments

So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar