Skip to content

Commit bea1802

Browse files
committed
pipes and redirections
1 parent 539b550 commit bea1802

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

unix/fully_walking.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,61 @@ To list the contents of a gzipped tar archive, use
6161

6262
To unpack files from a tar archive, use
6363

64-
$ tar -xzvf archivename
64+
`tar -xzvf archivename`
65+
66+
Try to archive the folder `Module_Unix` from the previous exercise!
67+
68+
You will notice a file called tutorials.tar.bz2 in your home directory. This is also a compressed archive, but compressed in the bzip format. Read the tar manual and find a way to decompress it
69+
70+
Hint: you can read the manual for any command using `man`
71+
72+
`man tar`
73+
74+
### Redirection
75+
76+
Some commands give you an output to your screen, but you would have preferred it to go into another program or into a file. For those cases you have some redirection characters.
77+
78+
#### Output redirection
79+
80+
The output from a command normally intended for standard output (that is, your screen) can be easily diverted to a file instead. This capability is known as output redirection:
81+
82+
If the notation `> file` is appended to any command that normally writes its output to standard output, the output of that command will be written to file instead of your terminal
83+
84+
I.e, the following who command:
85+
86+
`who > users.txt`
87+
88+
No output appears at the terminal. This is because the output has been redirected into the specified file.
89+
90+
`less users.txt`
91+
92+
Be careful, if a command has its output redirected to a file and the file already contains some data, that data will be lost. Consider this example:
93+
94+
`echo Hello > users.txt`
95+
96+
`less users.txt`
97+
98+
You can use the `>>` operator to append the output in an existing file as follows:
99+
100+
```
101+
who > users.txt
102+
echo "This goes at the end of the file" >> users.txt
103+
```
104+
105+
`less users.txt`
106+
107+
#### Piping
108+
109+
You can connect two commands together so that the output from one program becomes the input of the next program. Two or more commands connected in this way form a pipe.
110+
111+
To make a pipe, put a vertical bar `|` on the command line between two commands.
112+
113+
Remember the command `grep`? We can pipe other commands to it, to refine searches per example:
114+
115+
`ls -l ngs_course_data | grep "Jan"`
116+
117+
will only give you the files and directories created in January
118+
119+
Tip: There are various options you can use with the grep command, look at the manual!
120+
121+
Pipes are extremely useful to connect various bioinformatics softwares together. We'll use them extensively later.

unix/running.md

Whitespace-only changes.

0 commit comments

Comments
 (0)