It can also find strings by pattern or regular expressions, and also filter the output of commands, and much more.Īll these are done with instant speed, so it is very convenient to use. On Linux, this is accessible with one exact, simple but powerful grep command - grep stands for "global regular expression print". Feel free to ask any questions if you have any below in the comments.Often, programmers need to find a file that contains a specific line or a specific word in that line. We hope you have now enough knowledge on how to use grep command to find a file containing a specific text. Grep "^" -rns "/path-of-the-directory" Conclusion To search for lines that start with lowercase and uppercase letter, use the following syntax: To search for lines that start with a lowercase letter, use the following syntax: To search for lines that start with an uppercase letter, use the following syntax: mnt/grub.d/05_debian_theme:177: Ubuntu|Kubuntu)įind all Lines that Starting with Lowercase or Uppercase Letter mnt/grub.d/05_debian_theme:33: # Set a monochromatic theme for Tanglu/Ubuntu. mnt/grub.d/05_debian_theme:32: Tanglu|Ubuntu|Kubuntu) To display line numbers with matching words “Ubuntu”, use the grep command with -n option as shown below: If you want to search for two words “Ubuntu” and “Linux” in /mnt/grub.d directory, run the following command: To find all the lines that matches only whole words using the following syntax:įor example, find all the lines that matches for word “Ubuntu” in /mnt/grub.d directory. mnt/grub.d/05_debian_theme: # Set a monochromatic theme for Tanglu/Ubuntu. To ignore case when searching for a string, use grep command with -i option as shown below: If you want to display only search string without filenames, run the grep command as shown below: Grep -H -R ubuntu /mnt/grub.d/ | cut -d: -f1 You can also run the following command to display only filenames: You should see only filenames that match with search string: If you want to display the only filename, run the grep command with -l option: In the above output, you should see all the search string with the filename. mnt/grub.d/05_debian_theme: Ubuntu|Kubuntu) mnt/grub.d/05_debian_theme: Tanglu|Ubuntu|Kubuntu) Grep -r "search-string" "/path-of-the-directory"įor example, find all files that containing string called “ubuntu” in the directory /mnt/grub.d recursively, run the following command: To search for a specific string in all files located inside specific directory recursively, use the following syntax: Search All Files in a Specific Directory Recursively etc/nginx/win-utf:# use contrib/unicode2nginx/win-utf map instead. Grep: /etc/nginx/sites-enabled: Is a directory Grep: /etc/nginx/sites-available: Is a directory etc/nginx/nf: include /etc/nginx/sites-enabled/* etc/nginx/nf: include /etc/nginx/conf.d/*.conf etc/nginx/nf: # Uncomment it if you installed nginx-passenger etc/nginx/nf: #include /etc/nginx/naxsi_les etc/nginx/nf: # Uncomment it if you installed nginx-naxsi etc/nginx/nf: error_log /var/log/nginx/error.log etc/nginx/nf: access_log /var/log/nginx/access.log etc/nginx/nf: include /etc/nginx/mime.types etc/nginx/nf.1.4.1:rules_path = /etc/nginx/naxsi_les etc/nginx/koi-utf:# If you need a full and standard map, use contrib/unicode2nginx/koi-utf etc/nginx/fastcgi_params:fastcgi_param SERVER_SOFTWARE nginx/$nginx_version To search for a string called “nginx” in all the files located inside directory /etc/nginx/, run the following command: # Uncomment it if you installed nginx-passenger # Uncomment it if you installed nginx-naxsi To search all the lines that containing specific string in the single file use the following syntax:įor example, search for a string called “nginx” in the file /etc/nginx/nf, run the following command: You should see the grep manual page in the following screen: -l : Used to display filename without matching string.įor more information about grep comamnd, run the following command:.-w : Used to search for matching whole words only.-n : Used to display line numbers in the output.-h : Used to suppress the inclusion of the file names in the output. -r : Used to search directory recursively.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |