DEV Community

Cover image for WORKING WITH FILES IN CENTOS8
Frank Promise Edah
Frank Promise Edah

Posted on

WORKING WITH FILES IN CENTOS8

Image descriptionLet's assume you are a junior sysadmin in a company and as part of your on board process, you have been asked to perform some basic tasks in order to check your knowledge of the operating system. You have been asked to perform the following tasks:

  1. Find out how many CPU's are in the system and what type.
  2. Gather the logs
  3. Find out how many users are on the system.

At first, this might look quite challenging, but knowing what commands to use at the right time makes it easier! We are going to walk through each steps together and arrive at the right end!

Find out how many CPU's are in the system and what type.

  1. Log into the server using the credentials given. You can temporary assume root privilege using the sudo i command.

2.To know how many cpu's are on the system, use the cat command to print out the content of /proc/cpuinfo. This directory is where you can find all informations related to the CPU.

  1. In order to get the relevant information, use the head -5 command. This command shows you the first five lines of the /proc/cpuinfo.

Alternatively, if there are more than 1 CPU, you can use the grep command like this grep A 4 processor /proc/cpuinfo. Adding 'A', tells grep to print four lines after it matches the word 'Processor'.

Summary of task

cat /proc/cpuinfo
head -5 > /tmp/cpu
OR
grep A processor /proc/cpuinfo > /tmp/cpu
'>' tells the system to redirect the result into the file stated instead of printing it out.

Gather the logs containing today's information

Let's assume we want information on today's date, we can use the tail command to print out the recent logs from /var/log/messages. Run the following command:
tail /var/log/messages
__grep "Mar 3 " /var/log/messages > /tmp/logs

Find out how many users are on the system

To do this, we can use the wc command. This command is use to the lines in a line. To know how many users are on the system, run the following command:
wc -l /etc/passwd > /tmp/usernum

Now you see it is not as challenging as it seems from the beginning!

Suggestions on other ways this can be done will be highly welcomed

Top comments (0)