Or, we could pipe the output to the grep command and display only the lines of text that contain the word cdrom: We can then scroll through the output and find the cdrom group and its members. We can do this by typing the cat /etc/group command, which will display all the groups and their members on the system: For example, suppose that we would like to display the members of the group cdrom. Grep is most commonly used in conjunction with commands that produce a lot of output, so you can sift through that output for the lines that are important to you. Note that the grep command has listed the filename and the line of the text containing the keyword bob. The -r option specifies that the subdirectories will also be searched. In the picture above we can see that there are two occurrences of the word bob in the files inside the /home/bob directory. If we want to search the directory /home/bob for each occurence of the word bob, we can use the following command: ![]() The syntax is:įor example, if we want to search the file bobs_file.txt for each occurence of the word bob, we can use the following command: By default, grep prints the matching line of text. You can search a single file or a whole directory of files. The grep tool is used to locates files by scanning their content.
0 Comments
Leave a Reply. |