Intermediate shell commands
In the previous section, we used some basic commands in order to get used to Terminal. In this section, we will get familiar with more advanced commands, as follows:
echo
: Theecho
command allows you to display content that can be added to either a new or an existing file or to replace the content.- If you want to add content to an existing file, you can use
echo "content to be appended" >>file1.txt
. Or, you can useecho "this content will replace" > file1.txt
to replace the content of a file.
You can see the echo
command in use here:
Figure 2.6 – echo command
cat
: Thecat
command is normally used to read the content of a file, as illustrated here:
Figure 2.7 – cat command
You can use the cat
command and append the output to a new file using >>
. This is the same for any output—for example, you can use ls –la...