Linux Basics – Hands-On Guide

Linux Basics – Hands-On Guide

Linux is an operating system based on UNIX OS, having high security. 
For those of you who are beginner in Linux, please follow along:

Here are some basic and important commands to run on Linux terminal:

  1. To list the content of a directory
    • ls
    • ls -all
    • ll    i.e. long listing
  2. To view system date, time and timezone
    • date
  3. To see all Processes running on your Linux machine
    • ps
    • ps -ef
  4. to create new directory i.e. hadoop
    • mkdir hadoop
  5. to change/switch to new directory i.e. hadoop
    • cd hadoop
  6. to create new file i.e. mapreduce.txt inside a directory
    • touch mapreduce.txt
    • nano mapreduce.txt
    • vi mapreduce.txt
  7. to view content of a file
    • cat mapreduce.txt
    • more mapreduce.txt
    • head mapreduce.txt
      • this will show top 10 records of the file
    • tail mapreduce.txt
      • this will show the last 10 records of the file
  8. lets put some content in this file
    • nano mapreduce.txt
    • then copy paste below content [6 lines] and save the file
101,java
201,scala
301,python
401,R
501,SAS
601,sas
  1. Search specific word/content in a file ***very important
    • grep “word-to-search” filename
    • examples
      • grep “SAS” mapreduce.txt
      • grep -i “SAS” mapreduce.txt
        • -i is a flag that makes command case-insensitive i.e. Ignore Case
      • grep -n “SAS” mapreduce.txt
        • -n flag will print the line number of the file containing the match word
  2. Redirection Operator: > and >>
    • this command will copy and over-write content of one file to another
      • cat mapreduce.txt > spark.txt
    • this command will copy but won’t over-write content of one file to another , i.e. it will append content to end of existing content inside the file
      • cat mapreduce.txt >> spark.txt
  3. Pipeline Operator: |
    • this operator will pass the output of a command [on left hand side] as input to another command [on right hand side]
   ps -ef | grep -i "sh"
   ls -all | grep -i "hadoop"  

For some programming experience, one can also try for loops and conditional statements [if then else] in Linux.

for i in {1..10}

do

echo $i

done


Also having sound understanding of sed and awk/gawk commands will help you clear most of the Linux and Shell Programming interviews.


Rahul Aggarwal
http://guardiancoder.in

Senior Data Scientist and Gen-AI Engineer #DataScience #AI #RNN #CNN #GenAI #ChatGPT #LLMs

Leave a Reply

Discover more from Rahul Aggarwal's EdTech

Subscribe now to keep reading and get access to the full archive.

Continue reading