Writing, Reading, and Listing Files

So in the last post we talked about the command echo. Now we’re going to use it to create a file. At your terminal prompt, do:

Alpha:~ computerlamp$ echo "Hi there" >myfile

This took the output from the command echo “Hi there” and put it in a file called myfile. To see the contents of myfile, do:

Alpha:~ computerlamp$ cat myfile

On your terminal screen will appear:

Alpha:~ computerlamp$ cat myfile
Hi there

So the command cat can show you the contents of a file. But how do we know what files we have? That’s where the command ls comes in. If we execute ls, we see:

Alpha:~ computerlamp$ ls
myfile

The ls command lists the files you have. In the next blog post we’ll talk about directories, which are the containers of the files.

One thought on “Writing, Reading, and Listing Files

  1. Pingback: Nano! Creating, Changing and Saving Files - ComputerLamp

Leave a Reply

Your email address will not be published. Required fields are marked *