Creating and Reading Files
Explore how to create text files with the echo command and insert content using redirection. Learn to read file contents quickly with cat and navigate large files efficiently using less, more, and fewer commands to manage files in the command-line environment.
We'll cover the following...
We'll cover the following...
Creating files
The echo command takes text and prints it back to the screen. Run the terminal below to run the following command:
$ echo Hello there
We see the text we entered printed back to us. We use echo in scripts we write to display instructions or output to users. But we can also use it to insert text into files if we combine it with a redirection feature.
Let’s create a text file in our root directory that contains the text “Hello”. We call this file greetings.txt. At the prompt, we type the following: