regular expression – Internetblog.org.uk https://www.internetblog.org.uk Web hosting, Domain names, Dedicated servers Fri, 29 Jan 2016 11:05:52 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.5 https://www.internetblog.org.uk/files/2016/01/cropped-favico-32x32.png regular expression – Internetblog.org.uk https://www.internetblog.org.uk 32 32 Searching with GREP https://www.internetblog.org.uk/post/1566/searching-with-grep/ Fri, 23 Jul 2010 20:08:50 +0000 http://www.internetblog.org.uk/post/1566/searching-with-grep/ GREP, which stands for global regular expression print, is a sophisticated Linux/Unix tool that can serve many purposes, but one useful purpose on a dedicated server is its ability to search files and directories. With grep you can search within multiple files with relative ease. You can also parse printed screen data to simplify results.

To search a file, just enter “grep” followed by the search term and then the filename. For example, to search the file “httpd.conf” for the word “localhost”, you would type:

grep localhost httpd.conf

To use grep, to simplify printed screen lists, use the following format:

ls -al /usr/bin | grep make

This will list all of the files in the /usr/bin directory, but will only display those files that contain the word “make”. For more in-depth documentation, including use of regular expressions, type “man grep” from the command line.

Photo Source: Wikimedia Commons

]]>