User Tools

Site Tools


wiki:redirection

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
wiki:redirection [2015/11/16 12:05]
asa [head/tail - display first/last lines of a file]
wiki:redirection [2016/08/02 14:47] (current)
Line 65: Line 65:
 </​code>​ </​code>​
 Type the command and then, like above, type some text and finish with ''​ctrl-d''​ and check what happened. Type the command and then, like above, type some text and finish with ''​ctrl-d''​ and check what happened.
- 
-==== wc:  counting lines, words, bytes ==== 
- 
-The command 
-<code bash> 
-$ wc my_file 
-</​code>​ 
-will print the number of lines, words, and bytes in a file.  For example: 
-<code bash> 
-$ wc my_file.txt ​ 
-       ​1 ​      ​1 ​      5 my_file.txt 
-$ more my_file.txt ​ 
-test 
-</​code>​ 
-Here's the general form of the command: 
-<​code>​ 
-wc [file_name ...] 
-</​code>​ 
-What does this tell us? 
- 
-wc plays well with pipes. ​ What will the following command tell us? 
-<code bash> 
-$ ls | wc 
-</​code>​ 
-How would have we done this without the pipe? 
- 
-==== grep:  print lines that match a pattern ==== 
- 
-Suppose we would like to see which programs potentially handle zip files. ​ Such a program will likely have //zip// somewhere in its name. 
-We'll use the grep command for that: 
-<code bash> 
-$ ls /usr/bin/ | grep zip 
-</​code>​ 
-And we can combine it with wc: 
-<code bash> 
-$ ls /usr/bin/ | grep zip | wc 
-</​code>​ 
-The general format for the command is: 
-<​code>​ 
-grep [file ... ] 
-</​code>​ 
-and it also has a few options. 
- 
-==== head/tail - display first/last lines of a file ==== 
- 
-Sometimes we just want to peek at the beginning/​end of a file. 
-The command 
-<code bash> 
-$ head my_file 
-</​code>​ 
-will display the first 10 lines of the given file.  ''​tail''​ is analogous and displays the last 10 lines. 
-Both commands have an option that controls the number of lines that get displayed, e.g.: 
-<code bash> 
-$ ls /usr/bin | tail -n 5 
-</​code>​ 
  
  
wiki/redirection.txt ยท Last modified: 2016/08/02 14:47 (external edit)