Create Files from Parts of Other Files
Learn On Demand
Learn On Demand Pro Series

Time
1 hour
Difficulty
Intermediate

In this IT Pro Challenge virtual lab, you will learn how to use basic Linux commands to manipulate files and data sets to find data to use for reporting and analysis. You will become familiar with Linux commands such as ls, tac, head, and tail. These skills are essential for someone on a career path as a Linux administrator or security analyst.

Start your free 3-day trial and become one of the 3 million Cybersecurity and IT professionals advancing their career goals

Sign up with
Or

Already have an account? Sign In »

Overview

Lab Overview:

This hands-on lab provides a Linux administrator with an understanding of how to use some of the basic commands for reviewing and searching data within files and folders. You will learn to use the ls, tac, head, and tail commands, along with some useful wildcards and options. These are important skills for Linux administrators and security analysts.

Understand the scenario

You are a Linux system administrator. You need to combine parts of logs and command output into new files that can be used as reports, configuration files, and scripts. First, you will create the files and directories that you will use in the challenge, and then you will install the manpages. The manpages will serve as a reference if you need to review command usage and syntax. Then you will practice using the ls, tac, head, and tail commands with wildcards to extract the data you need and output to a new set of files.

Create necessary files and directories:

To set up your environment, you are provided a series of commands that allow you to build a file structure of relevant data for use during this lesson. You will use the mkdir, touch, and echo commands to build the file and folder structure and populate your files with various data sets.

Install the manpages:

Manual pages are, as it sounds, reference material that contains usage, options, and syntax details for Linux command-line utilities. This section will ensure that your Ubuntu Linux distribution has the necessary manual pages to perform this lab. The system installation is minimized for the lab environment, so you will have to download, uncompress, and install the manual pages. The lab instructions provide reference material to enable you to complete this task. Once you have installed the man pages, you will verify the installation.

Create a new file from an existing file by using the head and tail commands:

The head and tail commands are complementary commands that allow you to view the first part of a file (head) or the last part of a file (tail). These are useful commands, especially for a security administrator who needs to monitor log files as they are written to the system. For example, the tail command with the -f option will display the last ten lines of a log file as it is written to. For this task, you will create a new file that contains the first and last ten lines of a specified file. As an example, this would be practical in a scenario where you want to compare resource utilization at the beginning of a log file to the end of the log file.

Create a new file that contains a filtered list of existing file names:

In this section, you will learn about the ls command and how to use wildcards to list only specific file names from within a directory. The wild card options for the ls command allow you to specify pattern matching; for example, the second character in a file name must be a certain character or number. You’ll run the command that gets the desired result; then, you will output those results to a new file. Hint: question mark, brackets, and the asterisk will be useful for this task.

Create a new file that contains file names that begin with a lowercase letter:

Similar to the previous task, you will use the ls command with wildcards to get a very specific listing of the files in your directory. In this case, you will search for a pattern match of the first character of the file name, looking for any file that starts with a lowercase letter. Again, you will write the output of the list command to a new file. However, you’ll also be introduced to the tac command, which is basically the opposite of the concatenate (cat) command, which will allow you to reverse the order of your output.

Create a new file that contains part of an existing file:

In some cases, you may not be interested in the first set of lines within a file. For example, they may be boilerplate descriptions or standardized content that is not relevant to your goals. To extract only a portion of a file, you can use the tail command with an option that specifies which line to start from, then output from that point forward. In this task, you will craft the command to get your desired results and output those results to a new file.

Lab Summary Conclusion:

In this hands-on virtual lab, you will learn how to use some of the most basic Linux commands for listing specific file names and contents that can be output into new files for reporting or analysis use. You will become familiar with the ls, tac, head, and tail commands and use wildcards to get very specific results. These skills are essential for a Linux administrator and for security analysts and penetration testers that use the Linux platform.

Other Challenges in this series

  • GUIDED CHALLENGE: Search for Files by Using Wildcards
  • GUIDED CHALLENGE: Configure the Display of a File