Command to find a file in linux

The Linux 'find' command is one of the most important and much used command in Linux sytems to search and locate list of files and directories based on conditions you specify for files that match the arguments.  The following commands can be executed only if you have SSH access to server.

1. Find Files Using Name in Current Directory

Find all the files whose name is abc.txt in a current working directory.

# find . -name abc.txt


2. Find Files Under Home Directory

Find all the files under /var directory with name abc.txt.

# find /var -name abc.txt


3. Find Files Using Name and Ignoring Case

Find all the files whose name is abc.txt and contains both capital and small letters in /var directory.

# find /var -iname abc.txt


4. Find Directories Using Name

Find all directories whose name is 'test' in / directory.

# find / -type d -name test


5. Find PHP Files Using Name

Find all php files whose name is test.php in a current working directory.

# find . -type f -name test.php


6. Find all PHP Files in Directory

# find . -type f -name "*.php"


7. Command to find all starting with 'test' in /var folder

# find . -type f -name "test*"


8. Command to find a string inside the files  

grep -irl ‘<text to search for>’ <directory to search>/*

# $ grep -irl 'welcome' /var/www/*

This command will recursively search for the string in all folders mentioned in the path.

Last update:
2014-10-02 13:19
Sherin George
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.

Records in this category