Contents
How do you find files contain a text in Linux?
To find files containing specific text in Linux, do the following.
- Open your favorite terminal app. XFCE4 terminal is my personal preference.
- Navigate (if required) to the folder in which you are going to search files with some specific text.
- Type the following command: grep -iRl “your-text-to-find” ./
How do I find all files containing specific text on Unix?
How do I find all files containing specific text on Linux?
- -r – Recursive search.
- -R – Read all files under each directory, recursively.
- -n – Display line number of each matched line.
- -s – Suppress error messages about nonexistent or unreadable files.
How to find and delete files in Linux?
If you only want to find files (not delete), just remove the options -delete or -exec rm {} \\; or -exec rm {} + in the above commands. For example, the following command will only find the files that contains the string “install” in their names: 2. Find And Delete Files That “does not” contain specific text in their names in Linux
How to delete files that contain specific text in their names?
Find Files That Contains A Specific Text In Their Names In Linux If you only want to find files (not delete), just remove the options -delete or -exec rm {} \\; or -exec rm {} + in the above commands. For example, the following command will only find the files that contains the string “install” in their names:
How to find all files containing specific text in Linux?
If you would prefer to use the find command, you can use the following command syntax: Once again, add -i to the grep portion of the command to ignore case. The find and grep methods both work well. Use whichever one you prefer. In this guide, we saw how to find all files containing specific text in Linux.
Is there a command to delete a file?
However, the -delete option may not available on all find versions. Hence, we can use the xargs command as follows too: -print0 – Force find command to print the full file name on the standard output, followed by a null character (instead of the newline character that -print uses).