

Example 1 $ grep -rnw '/path/to/search/in/' -e "text to find"
#LINUX FIND FILE CONTAINING STRING HOW TO#
The -exec command allows you to execute an action against all of the files that are output from the find command.įind a file named file1 and change permissions to 644:įind / -name “file1” -exec chmod 664 How to Use the Locate Command On LinuxĪn alternative to the find command is the locate command.

In order to find a file that is exactly 1GB in size, simply type in the phrase:įind / -size -1G Performing Actions based on Find Output SImply use the -size flag with the following size conventions:

This will list all files with 755 permissions:įind can filter files based on their size. We can even find files based on permissions. The -user and -group flags can be used to find a file located by a specific user or groupįind all files owned by group “mc” with the case sensitive name “mirrorlist.txt” Let’s find a file modified more than 5 days ago:įind / -mmin +25 Finding Files by User or Group You can find files based on access time (-atime), modified time (-mtime), and change time (-ctime) flags. In order to find a regular file called “file1” use:įind -type f -name “file1” Finding Files by Time If you want to search for files by type, you can do so with the following command: This will return all files that don’t contain the string “file” in them, and is applicable to other strings. What if we only want to return files with names that don’t contain a certain string? Then we will use: Let say you want to search for a string is in. Besides grep, you can also use other utilities such as awk or sed. If you want to search for fixed strings only, use grep -F 'pattern' file. This search will return both uppercase and lowercase results: The usual way to do this is with grep, which uses a regex pattern to match lines: Each line which matches the pattern will be output. If we want to run a case insensitive search, we can do this: This is a case sensitive search, so it returned just one file: In order to find a file by name, simply type:
#LINUX FIND FILE CONTAINING STRING MANUAL#
This will open the handy “find” manual page for you. If you are ever lost, just type the phrase: See Also: (Live Webinar) Meet ServerMania: Transform Your Server Hosting Experience How to Use the Find Command On Linux Getting StartedĪlways remember that Linux has your back! There is a handy manual page for every command. The directory contains each of the following files: We’re going to navigate into a directory with the following files in order to demonstrate what will be returned when various commands are used.

This article will walk you through how to locate files on Linux using the find and locate commands. Linux file navigation may seem daunting at first, but it’s quite easy once you know the right commands to use.
