Will513r / command-line-VWC

1 stars 0 forks source link

Redirect input and output using `>`, `>>`, and `|` #15

Open Will513r opened 11 months ago

Will513r commented 11 months ago

Summary

Learn how to redirect input and output in the shell using the >, >>, and | operators. Mastering these techniques allows you to manipulate how data flows between commands, files, and other I/O streams.


Description


Learning Tasks

  1. Understanding I/O Redirection:

    • Learn what I/O redirection is and why it is essential for efficient shell scripting and command-line use.
  2. How to Use > for Overwriting:

    • Understand how to use the > operator to redirect output from a command to a file, overwriting the file if it already exists.
  3. How to Use >> for Appending:

    • Learn how to use the >> operator to append output from a command to an existing file.
  4. How to Use | for Piping:

    • Learn how to use the pipe (|) operator to send the output of one command as the input to another.
  5. Hands-on Practice:

    • Exercise 1: Use the > operator to redirect the output of ls to a file, thereby saving the listing of a directory to that file.
    • Exercise 2: Utilize the >> operator to append the output of another ls command to the same file.
    • Exercise 3: Employ the | operator to pipe the output of ls into grep to filter the results.
    • Exercise 4: Combine multiple redirection operators in a single command line to perform complex tasks.
  6. Troubleshooting:

    • Go through common pitfalls and problems that might occur while redirecting I/O and how to solve them.

Learning Goals


Priority

Will513r commented 11 months ago

The > >> are used for saving information to files that are created or need to be created. An | is a way to focus on the information you need. It was explained to me it's like an magnifying glass.

tupleHunden commented 11 months ago

I wouldn't really say | is like a magnifying glass, it's more like a conveyor belt; moving the outputs of the previous operation into the next.

cat package.json | grep "thing_to_search"

This will print the contents of package.json to stdout, but instead of actually printing it to stdout, it will send the response into grep which will search over the results.