Introduction
This challenge focuses on analyzing command usage history in a Linux system while practicing data stream redirection. By completing this task, you will enhance your text processing skills, familiarize yourself with common Linux commands, and gain a better understanding of input/output manipulation in Linux environments.
Analyze Historical Commands Using Stream Redirection
Requirements
Your task is to analyze a file containing a record of command usage. You need to identify the top three most frequently used commands in the file and save the results in /home/labex/project/result. This task must be accomplished using stream redirection techniques.
Tasks
- Process the
data1file located in/home/labex/project/using theawk,sort,uniq, andheadcommands in combination with stream redirection. - Redirect the top three most frequently used commands to
/home/labex/project/result. - Format the results to include both the number of occurrences and the command, as "count command" (e.g., "100 ls").
Example
The sample content of the data1 file:
895 echo $?
896 openstack compute service list
897 cd /home/chy/openstack/
898 . admin-openrc
The sample output format in /home/labex/project/result:
150 openstack
114 systemctl
105 ls
Only the top three most frequently used commands should be included in the result file.
Hints
You may need to use awk to extract the command from the file content. Here are some useful awk examples:
awk '{print $2}': Prints the second field of each line.awk '{print $1, $2}': Prints the first and second fields of each line.
Summary
In this challenge, you have practiced analyzing command usage history while applying Linux stream redirection techniques. This exercise has improved your text processing abilities, familiarity with common Linux commands, and understanding of input/output manipulation. These skills are valuable for system administrators and power users working in Linux environments.



