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:
- To list the content of a directory
- ls
- ls -all
- ll i.e. long listing
- To view system date, time and timezone
- date
- To see all Processes running on your Linux machine
- ps
- ps -ef
- to create new directory i.e. hadoop
- mkdir hadoop
- to change/switch to new directory i.e. hadoop
- cd hadoop
- to create new file i.e. mapreduce.txt inside a directory
- touch mapreduce.txt
- nano mapreduce.txt
- vi mapreduce.txt
- 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
- 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
- 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
- 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
- this command will copy and over-write content of one file to another
- 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.
Leave a Reply