Helpful Linux commands

As a sys admin, I usually use commands that help process logs, config files and datas in various reasons. In my today’s post I will introduce to you some of these Linux commands that will help you manage logs, but, let’s first introduce my must to know command that let you understand all linux commands.

Man

If you want to read a command’s manual, without opening search engines, the best way is to directly read the command’s manual directly. Just write the word “man” before the command and it’ll print the manual in the terminal.
Here is an example :

CD(1P)                        POSIX Programmer's Manual                        CD(1P)

PROLOG
       This  manual  page is part of the POSIX Programmer's Manual.  The Linux imple‐
       mentation of this interface may differ (consult the corresponding Linux manual
       page  for  details of Linux behavior), or the interface may not be implemented
       on Linux.

NAME
       cd — change the working directory

SYNOPSIS
       cd [-L|-P] [directory]

       cd -

DESCRIPTION
       The cd utility shall change the working directory of ...

Now, you know man command, let’s talk about the first command. We

Less

less is a command that reads a file’s content and show it in the screen.
Opening a file using “Less” and then hitting / and typing the word you want to search for is faster than searching for it using vim. if you add +F flag, the output will be streamed like tail -f command. For example : dmesg | less +F. But, the difference with tail -f is, that you can hit Ctrl+C and navigate in the output strings, you can hit / to search for a specific word or copy the error messages.

This command dmesg | less -p "failure" will output text only if this text contains the word “failure”.

Awk

In 1977, three guys written the awk program and they named it based on their names,  Alfred AhoPeter Weinberger, and Brian Kernighan.
AWK is a text manipulation toolkit running in terminal.

This is an example for searching text in a file: awk '/redux/ { print $0 }' package.json this will return lines in package.json that contains redux

    "react-redux": "^7.2.5",
    "redux": "^4.1.1",
    "redux-saga": "^1.1.3",
    "redux-saga-devtools": "^0.3.0",

Adding condition is very useful. For example, looking for files created in July ls -l | awk '$7 == "jul" END { print }'.

WC

If you want to know how many files there are in a folder (the last command), you can run this command ls -l | awk '$7 == "jul" END { print }' | wc -l.

But if you are on a based arch linux distro and you want to know how many packages are installed in your system you can add wc -l in the last pipe of this command pacman -Qi | awk '/^Name/{name=$3} /^Installed Size/{print $4$5, name}' | sort -h | wc -l

That’s it for this light post, folks! Hope you enjoyed it. Please let me know if you have a useful command in comment below and thank you for the support.

You Might Also Like
2 Comments

Leave a Reply