Key Concepts

Review core concepts you need to learn to master this subject

Append Redirect shell command

# This command will append "Hello World!" to greetings.txt echo "Hello World!" >> greetings.txt

The >> shell command is used to redirect the standard output of the command on the left and append (add) it to the end of the file on the right.

Redirection
Lesson 1 of 1
  1. 1
    Up until now, we have run commands in the command line and received a stream of output in the terminal. In this lesson, we’ll focus on input and output (I/O) redirection. Through redirection yo…
  2. 2
    How does redirection work? $ echo “Hello” > hello.txt The > command redirects the standard output to a file. Here, “Hello” is entered as the standard input, and is then redirected to the file **…
  3. 3
    $ cat deserts.txt > forests.txt > takes the standard output of the command on the left, and redirects it to the file on the right. Here the standard output of cat deserts.txt is redirected to **f…
  4. 4
    Now we know how to overwrite a file’s contents, but what if we want to be able to add to a file without losing the original text? We can use the >> command! $ cat deserts.txt >> forests.txt >> t…
  5. 5
    $ cat < deserts.txt < takes the standard input from the file on the right and inputs it into the program on the left. Here, deserts.txt is the standard input for the cat command. The standard…
  6. 6
    | is a “pipe.” The | takes the standard output of the command on the left, and pipes it as standard input to the command on the right. You can think of this as “command to command” redirection. …
  7. 7
    $ sort continents.txt sort takes the standard input and orders it alphabetically for the standard output (it doesn’t change the file itself). Here, the continents in continents.txt will be l…
  8. 8
    $ uniq deserts.txt uniq stands for “unique.” It filters out adjacent, duplicate lines in a file. Here uniq deserts.txt filters out duplicates of “Sahara Desert”, because its duplicate directly f…
  9. 9
    $ grep America continents.txt grep stands for “global regular expression print.” It searches files for lines that match a pattern and then returns the results. It is also case sensitive. Above, …
  10. 10
    $ grep -R Arctic /home/ccuser/workspace/geography /home/ccuser/workspace/geography/deserts.txt:Arctic Desert /home/ccuser/workspace/geography/oceans.txt:Arctic Ocean grep -R searches all files i…
  11. 11
    sed ‘s/snow/rain/‘ forests.txt sed stands for “stream editor.” It accepts standard input and modifies it based on an expression, before displaying it as output data. It is similar to “find and…
  12. 12
    Congratulations! You learned how to use the command line to redirect standard input and standard output. What can we generalize so far? * Redirection reroutes standard input, standard output, an…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo