You want to use the output of one Linux command as the input to another command.
Use the pipe command, which is the bar symbol (|) on your keyboard, to pipe the output of one command to another. For example:
$ ls -l *.py | grep Jun -rw-r–r– 1 pi pi 226 Jun 7 06:49 speed.py |
This example will find all the files with the extension py that also have Jun in their directory listing, indicating that they were last modified in June.
Discussion
At first sight, this looks rather like output redirection using > (Recipe 3.27). The difference is that +>_ will not work where the target is another program. It will only work for redirecting to a file.
You can chain together as many programs as you like, as shown here, although this isn’t something you will do often:
$ command1 | command2 | command3 |
See Also
See also Recipe 3.24 for an example of using grep to find a process, and Recipe 3.23 to search your command history using a pipe and grep.