Linux commands every admin should know (Part I)

Category : Guides
By :admin
Aug 05, 2013

Today we are going to talk about sundry Linux command line utilities which kicks off the series of articles dedicated to commands every admin should know. The articles are aimed primarily to inexperienced users and some passages may appear to be spelling out the obvious things or oversimplified (and therefore a bit inaccurate). Some of the utilities are included in blank versions of OSs, some need to be installed additionally. 

uname -a

This command displays general system information, namely: kernel name, hostname, kernel release, kernel version, processor architecture type and operating system name. It does not display the Linux distribution name and version; in order to find that out you need to see the contents of the /etc/*-release file. It is redhat-release for Centos/Fedora/RHEL and debian-release for Debian/Ubuntu – matters little which exactly since we can set the mask *. So, using the already mentioned cat command, the answer is yielded by:

cat /etc/*-release

 

uptime

Uptime command displays duration of uptime, in other words, for how long the system has been uninterruptedly running; it also shows how many users are logged in and CPU load average (for the last 1, 5 and 15 minutes). One unit of the load average value represents a “normal” load of one CPU core. So whereas it is an alarming situation to have 1.40 1.30 1.22 if there is 1 core CPU, there is no need to worry if you have 2 core CPU, let alone 4 core one. In addition, although, as we said, 1 unit per core means normal work, it is recommended to avoid continuous operation on that load level and set the bar 0.2-0.3 points lower. Thus there will be emergency provisions, if you will, and in case of load spikes server may handle them (at least for some time) instead of going offline immediately.

 

top

This command displays information about top CPU processes. If the system starts working slower and you have no clue why, top will give the explanation. The displayed information is periodically updated as the values in the summary part and in the process list change. Let’s begin with the summary part at the head of the output and then have a look at every column of the process list and see what it represents.

PID stands for process ID. Every process has its ID. If you want to monitor only some processes, you can set flag -p and recite up to 20 needed PIDs (top -p23,43,2343).

User – the owner of the process. As well as every process, every user and group has its ID. Flag -u shows the processes owned by the specified user. The user can be specified either by the username (top -u cherokee) or by UID (top -u 989). The UID, GID (ID of the user’s primary group) and other groups the user belongs to can be looked up via command id -a (id cherokee).

PR – current priority of the process.

NI – nice value. Nice value can be set within the range between -20 to 19 and determines priority of the task. -20 means the highest priority, 19 means the lowest priority. Suppose you need to unzip a really big archive on a system with a weak processor or to convert an avi video file to mp4. Tasks like that require a lot of CPU time and by default an operating system does not allocate as much CPU resources to this one single process as it can. Reducing the nice value increases the priority of the process thus speeding up its execution. In order to change the nice value of the running process you need to use renice command (renice -n -15 -p 2343).

VIRT – the virtual size of the process (in KB). VIRT shows how much memory the task can access at the moment.

RES (resident size) represents how much memory the task is using at the moment.

SHR (shared memory) shows how much memory is shared with other processes and how much memory is mapped. For instance, if process requires some functions of some library, the functions will be loaded to memory and be counted under resident size (RES) whereas the whole library will be mapped and its size be added to SHR column.

S column displays states of the processes. Processes can assume the following states: running (R), sleeping (S), sleeping uninterruptedly (D), traced (T) and zombie (Z).

%CPU shows the percentage of CPU time usage by the process.

%MEM shows the percentage of memory usage by the process.

TIME+ column displays how much CPU time the process has already used.

COMMAND displays name of the process executable file.

The first row of the summary part shows uptime, number of logged in users (the key words are “logged in” here: if there are ten users in the system (root, user1, user2, etc.) and only two people are logged in as root, the users value will show 2) and load average (it has been explained at the Uptime paragraph above).

The second row of the summary part (tasks) displays the total number of tasks, and distribution of the tasks according to the states of processes.

The third row (Cpu(s)) shows CPU time spent in user space (us), in kernel space (sy); CPU time spent on processes with low priority (ni), CPU idle time (id), wait time (the amount of time spent on waiting for I/O) (wa), CPU time spent handling hardware (hi) and software (si) interruptions, and finally steal time (st). Steal time value shows how much CPU time was stolen by hypervisor from the virtual machine.

The next row (mem) shows the total amount of memory, the amount of memory which is used, free and in buffers. Buffer is a memory space which temporarily stores data during input/output (I/O).

The last row (swap) displays the total SWAP size, used SWAP, free SWAP and the amount of cached memory. Files that were recently read from the hard disk are stored in cache so that next time they are needed it would be possible to read them from RAM which is way faster than accessing them from hard disk again. The kernel monitors the cache size and if system needs more free memory, the cache is cleared – its contents are transferred to SWAP (if SWAP is available) or get removed (if SWAP is unavailable or full).

In conclusion, there are other utilities like top (e.g. htop, atop) which are more user friendly but not usually included in blank OS templates by default and need to be installed additionally.

To be continued…

In case you have ordered one of our cheap Linux VPS and have difficulties managing it, you can order the Full management option where we will help you with your server.

Spread the love

Real Clients Feedback

250+5-Star Ratings
7+YrsCollecting Reviews

SiteValley.com is rated 4.8 / 5 based on 329 Reviews »

Logo

Ready to work together towards your success?

We love taking your call.