Not much is usually known by a unix/GNU Linux newbie about the potential power of echo. echo can be used on command line or used within a shell script. The later usage is more common and actual powerful usage of echo is done only within the shell scripts.
echo Command : Basics
echo not only echoes the text. The name of the utility points to a bit lesser capability.
There is not much to write about the examples given in the echo™s manual page. One can run man echo
to read and master echo. This guide covers only some practical commons which we can use on, for example SSH.
---
echo Command : Practical Examples For SSH
We are providing only few examples of echo here. First one is to list only the files with certain extension at certain location. Some times on SSH we need to list only the .conf
file, just for example; if we need to list all the .conf
files at /etc/nginx
location, we can change directory there and run :
1 | echo *.conf |
This will list all the files under that directory :
1 | echo * |
we can count them :
1 | echo * | wc -w |
As we written before, echo can be used to empty any file, for example, we want to empty /etc/nginx/nginx.conf
, then we can do this :
1 | echo ' ' > /etc/nginx/nginx.conf |
>
writes data to an exiting file. >>
is a kind of forcing. It will either overwrite or create a new file.
In the reverse way, we can write stuffs in the file :
1 | echo -e "server \t{\n\tuser\twww-data;\n\terror_log\tlogs/error.log notice;\t\n\t} |
\t
, \n
, -e
are explained in the man page of echo. This ends the story with echo. Obviously, the commands can be combined or piped. One example of unix piping is given in the example, a bit practice will give more ideas on how to use echo.