You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+4-17
Original file line number
Diff line number
Diff line change
@@ -221,23 +221,12 @@ For example, the following will send the `ls` output to `head` so that only the
221
221
$ ls -l | head
222
222
```
223
223
##Input/Output Redirection
224
-
I/O redirection is a handy tool that allows the user to send the output of a command somewhere other then the screen or even have a command accept input from somewhere other than the keyboard.
224
+
I/O redirection allows the user to send the output of a command somewhere other then the screen or even have a command accept input from somewhere other than the keyboard.
225
225
###Output Redirection
226
226
Standard output redirection uses the symbols `>` and `>>`. <br>
227
-
Most commands such as `ls` send their results to standard output, which prints to the screen.
228
-
Instead of printing to the screen we can redirect the standard output to print into a file.
229
-
The command goes before the symbol and the file goes after the symbol, as follows:
227
+
For example, the following will send the output of `ls` into the file instead of printing to the screen.
230
228
```
231
229
ls > files.txt
232
-
```
233
-
If we ran `ls` on its own we may get a results such as:
234
-
```
235
-
$ ls
236
-
file1.cpp sample.txt
237
-
```
238
-
But if we run the above command with output redirection, there will be no output to the display, the output will be in a file, such as:
239
-
```
240
-
$ ls > files.txt
241
230
$ cat files.txt
242
231
file1.cpp sample.txt
243
232
```
@@ -247,8 +236,7 @@ If the file already exists, then the contents of the command will overwrite what
247
236
To avoid overwriting a file, the `>>>` command will do the same thing as the `>` command except it will append to the end of the file instead.
248
237
###Input Redirection
249
238
Standard input redirection uses the symbol `<`. <br>
250
-
Just like standard output redirection, the command goes before the symbol and the file that the command will be getting its input from goes after the symbol.
251
-
Running the command `sort` with `<` will cause sort to access the input necessary to execute from the input file instead of standard input, such as:
239
+
For example, the following will cause `sort` to access its input from the file instead of the keyboard.
252
240
```
253
241
$ cat files.txt
254
242
a
@@ -264,8 +252,7 @@ But we can combine I/O redirection into one command line, such as:
264
252
```
265
253
$ sort < files.txt > files_sorted.txt
266
254
```
267
-
Notice that nothing got printed to the screen.
268
-
That is because the output was now sent to the files_sorted.txt file.
255
+
The output is now being sent to the files_sorted.txt file.
269
256
###Advanced Redirection
270
257
Adding a `&` with the `>` symbol will result in redirecting both standard out and standard error.
271
258
For example, running the following command on a file named "test.cpp" that prints the string "stdout" with `cout` and the string "stderr" with `cerr` will result in the following output:
0 commit comments