You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Now that we know how to move about our file system, it's time to start interacting with some of our files! For this portion, we'll start in our c2s2 folder from before, and assume that we have another empty folder named test inside of the c2s2 folder:

cd ~/c2s2
ls

We'll also start by creating a file called foo.txt with the text "foo bar" inside of it. We'll use the following command to do this - don't worry too much about it right now, we'll cover it later, but we can think of it as sending "foo bar" to the new file:

echo "foo bar" > foo.txt

Feel free to also do this with a code editor, if you've used one already!

For the sake of having another text file that's somewhat larger - we'll use the King James Bible, which you can store in a text file named james.txt with the following command (don't worry, we'll cover this later as well):

wget https://www.gutenberg.org/cache/epub/10/pg10.txt -O james.txt

Viewing Files

To view the text of a file in the terminal, the first command we can use is the cat command (short for concatenate), which takes in as an argument the file we want to view the text of, and simply prints it all to the terminal:

cat foo.txt

Note how this works well for short files, but not as well for large files - if you try running cat james.txt , you'll quickly get a very long output that's hard to understand all in the terminal! Instead, we can use a different command to better parse the output.

One of the oldest commands is the more command, which can help incrementally show you more of a file at a time:

more james.txt

Here, you can scroll with the arrow keys, and exit by pressing "q". However, the output still remains on the terminal, and scrolling leaves something to be desired. To add on to this, many systems have the less command, which we recommend:

less james.txt

Many of the controls are the same, but you can now scroll with your mouse/trackpad, and the output isn't left on the terminal at the end.

If your terminal every gets too cluttered for your liking, you can use the clear command to get clear away the history from the terminal and start a new prompt at the top

Copying and Moving Files

In addition to viewing files, we can also copy and move their contents around!

  • No labels