Lab 6: Input Output Redirection
Objective Focus
- Understand and use essential tools
- Create and edit text files
- Use input-output redirection (>, », |, 2>, etc.)
Official RHCSA EX200 Exam Objectives
Looking At File Content as Terminal Output
$ cat
- concatenate files and print on the standard output
$ less
- allows a user to partially display content of a file
$ more
- has less options than $ less
$ head
- output the first part of files, default is first 10 lines
$ tail
- output the last part of files, default is last 10 lines
Understanding Input and Output Redirection
Input | Output | Error |
---|---|---|
< | >, » | 2> |
$ out < in | $ in > out | $ in 2> errout |
$ in » out |
Example Use Cases
$ grep -i "error" < samplelog.txt
Download sample file here!
$ ip a > pcinfo.txt
$ hostname >> pcinfo.txt
$ hostname123 2> errout.txt
How to use pipes “|” in Linux
Using the “|” character is a form of redirection. It allows you to take output from one command to another.
$ cmd1 | cmd2 | cmd3 |.....|cmd_x
Example Use Cases
$ ip a | grep -i "inet" | awk '{print $1,$2}'
The above example shows us how we use available tools on the system for redirection. And how We could also redirect this output to a text file to share.
Redirections are very important to completing daily tasks in linux!
That’s it for lab 6!