14/180: Linux powerful Commands for System administration

Navneet Ojha
4 min readApr 1, 2021

--

Today is 14th day of my challenge of 180 days streak. Very tired today. It’s 11:30 already, just got free from office. Hectic day, but then this challenge must go on. Today I am going to discuss more on Linux commands, I have already covered Linux basic commands in my previous blog. Today we are going to learn the stuff from a system administrator perspective.

Let’s begin with few Filters / Text Processor Commands

awk: is for data extraction. Let’s say I have a file having list of names and the names consists of first and last name like

  1. Navneet Ojha
  2. Jeni Kaur
  3. Kenny Parker …..
  4. …………….and so on
awk '{print $1}' filename

The above command will print the first column in the file. i.e. the first names from the file.

//it will print the send column
awk '{print $2}' filename
// this command file print first and 3rd column of the list
ls -l | awk '{print $1, $3}'
//print last column
ls -l | awk '{print $NF}'
//awk can do search for you, it will give you that particular row
awk '/keyword to be searched/{print}' filename

grep/egrep: It process text line by line and show the line which matches.

grep keyword filename
grep -c keyword filename // -c will show the count of occurances
grep -i KEYword filename //-i ignore case
grep -n keyword filename //give line numbers also
grep -vi keword filename | aw '{print $1}' //will give only first col
ls -l | grep Desktop //give matched keyword from list
egrep -i "keyword1|keyword2" filename

sort/uniq -> filters out repeated lines

sort -> sorts in alphabetical order.

sort file | uniq //alone uniq will not work, it is required to use sort with this.
sort file | uniq -c //give counts for each.

wc: Read input newline count, word count, byte count.

Linux File editor: Though there are many file editors, but I will basically talk about vi editor. Usage of vi editor:

  1. Supplies command for Inserting and Deleting text
  2. Replacing Text
  3. Moving around the file
  4. Finding and Substituting strings
  5. Cutting and Pasting

Basic vi command:

  1. i -> insert
  2. r -> replace
  3. d -> delete
  4. :q! -> quit without write
  5. :wq! -> quit with save

Another very powerful command is sed

“sed” command

  1. Substitute command
  2. Replace a string a file with new string
  3. Find and Delete
  4. Remove empty lines
  5. To replace tab with spaces
  6. Show defined lines from a file
sed 's/keyword/replacewith' filename
sed 's/keyword/replacewith/g' filename //replace globally
sed -i 's/keyword/replacewith' filename //if want to insert changes in file
sed 's/keyword/d' filename //delete all lines having keword
sed 's/^$/d' filename //remove empty lines
sed 's/\t/ /g' filename //remove tabs

User Account Management

  1. useradd
  2. groupadd
  3. groupdel
  4. usermod

Files: /etc/passwd, /etc/group, /etc/shadow

Monitor User

  1. who -> to see how many people are logged in to system
  2. last -> last time user logged in
  3. w -> almost same as who, with some more information
  4. id -> give information about the user

Talking to User

  1. users ->users who are logged in
  2. wall -> Write message to all users.
  3. write -> write message to particular user

Linux Directory Service, linux account authentication

  1. local account
  2. Domain / Directory Account
  3. Windows = Active Directory
  4. Linux = LDAP -> protocol to authenticate against directory.
  5. IDM -> Identity manager

System Utility Commands

  1. date -> shows date
  2. uptime -> how long system was up for
  3. hostname
  4. uname
  5. which -> location of command
  6. cal -> calender
  7. bc -> binary calculator

Processes And Jobs

Application = Service

  1. Script -> written in files and packages
  2. Process -> when your application generates process id
  3. Daemon -> also process run always
  4. Threads -> Service Process -> thread 1, thread 2 …
  5. systemctl or service
  6. ps -> allows you to see the process
  7. top -> system resources for monitoring
  8. kill -> stop process by process id
  9. crontab -> schedule processes
  10. at -> like crontab

Process Management (bg, fg, nice)

  1. bg -> background
  2. fg -> forground
  3. nice -> prioritize the process

System Monitoring

  1. df -> disk partition info
  2. df -h -> disk partition info in human readable format
  3. iostat -> input out statistics {iostat 1 (refresh every 1 second)}
  4. free -> gives physical memory
  5. dmesg -> issues related to system hardware

Log Monitoring

Log Directory = /var/log

  1. boot -> when system boots up logs are generated
  2. chronyd = NTP
  3. cron
  4. maillog
  5. secure -> logging in logout activity
  6. message -> to monitor system messages
  7. httpd
  8. cat /proc/cpuinfo -> get cpu info
  9. cat /proc/meminfo -> get memory info

--

--

Navneet Ojha
Navneet Ojha

Written by Navneet Ojha

I am Indian by birth, Punjabi by destiny. Humanity is my religion. Love to eat, travel, read books and my million dreams keep me alive.

No responses yet