On a Linux dedicated server, the shell provides a powerful arsenal of commands for you to manage your system. Used in isolation, these commands can be very effective. Used in combination, you can truly unlock the power of your system.
There are a few ways to string commands together. One of the most basic tools you can use is the “|”. Often called a pipe, this single character on your keyboard allows you to push the output of a command into another command. For example, if you wanted to pipe the output of the “ls” list command to Grep so that you could search for the word “patch”, it would look something like this:
ls -al | grep patch
You can even pipe more than two outputs in a string. For example, to display the contents of a file, search it for certain words, and then paginate the results, you would enter something like:
cat filename.txt | grep dates | more
Another tool you can use is the “>”, which allows you to write the output to a file. Using the first example, you would type:
ls -al | grep patch > patchfiles
This will create a file called “patchfiles” containing the list you queried. To write to the end of the list rather than overwriting it, use an extra “>”.
ls -al | grep patch >> patchfiles
By extending the Linux command capabilities, you can manage your server even more effectively and efficiently.
- Extend Linux Commands with a Pipe
- List All Linux Commands with Compgen
- Learning to Use Linux Commands
- How to Rename Multiple Files in Linux
- 3 ls* Commands You Should Know