This hands-on lab provides a Linux administrator with an understanding of how to use common Linux commands and utilities to view data within log files. You will gain experience with the head and tail commands, which are complementary commands that will show you the beginning of a file or the end of the file. Then you will be introduced to the number line (nl) command and the tac command. The nl command allows you to display the output of a file and numbers the lines for you. The tac command displays the output of a file, with the rows of data in reverse (i.e., the bottom line becomes the top line). Finally, you gain experience using the powerful text manipulating utility, awk. The awk utility allows you to search for and match patterns in your file, and then you can take actions, such as replace the data or output save only what is matched.
Understand the scenario
You are a UNIX/Linux system administrator. You are tasked to review log files on an Ubuntu system and generate specifically formatted output. You will use common Linux command-line utilities for reviewing logs from different perspectives and saving the data to new output files for later use.
Display the beginning and end of a file:
In this section, you will learn about the complementary Linux commands, head, and tail. The head command allows you to view a portion of the beginning of a file; whereas, the tail command allows you to view a portion of the end of a file. You will also learn some of the command-line switches that are available to control your desired output.
Configure the display of lines by using the nl and tac commands:
For this task, you will learn about the number line (nl) command and the tac command. The nl command is useful if you want to apply a numbered order to the contents of a file. You may be familiar with the concatenate (cat) command, for reading the contents of a file or appending files together. In this lesson, you’ll learn about the tac command, which has the same functionality of the cat command, but it performs the task in reverse (hence the name).
Select and print a column by using awk:
Finally, you’ll get some hands-on experience using the awk utility. The awk utility is quite powerful for searching and manipulating the contents of a file. This tool is primarily used for scanning and processing data. You will learn how to craft a statement in awk, which can be used to replace pattern matched strings or output very specific contents of a file.
Lab Summary Conclusion:
In this hands-on virtual lab, you will learn how to use some of the most basic Linux commands and utilities. You will learn about the head, tail, nl, tac, and awk commands. This lab is ideal for Linux administrators or security analysts that will use Linux systems. The skills you will learn in this lab will help establish a strong foundation for using the Linux command-line interface.
Other Challenges in this series
- GUIDED CHALLENGE: Find Files by Using File Name Generators
- ADVANCED CHALLENGE: Can You Create Files from Parts of Other Files?