Linux Basics

Linux Basics

·

5 min read

What is LINUX ?

--Linux is open source & free - Derived from UNIX, written in C - low level language

--Terminal - It's the place where you can interact with OS using commands.

--All the distributions providers [ ubuntu, linux mint, Centos, Fedora, Redhat, Kali linux, etc] they will take the kernal & they will modify & release their own linux version. That means "ubuntu, linux mint, Centos, Fedora, Redhat,Kali linux, etc ] all are Linux only

Basics Linux commands:

cd -- moves to home directory (change directory) , used to move to different directory.

man -- manual (like an user manual)

help -- provide information about each command

ls -- To list files and directories under a folder.

ls -lh -- human readable

Wildcards:

ls *.Txt - - list all the Txt files

ls ?.Txt -- list only Txt file which has one character

eg: a.txt b.txt

ls file[1234].txt

create and delete (File/Directory)

touch filename --create a file

rm filename --remove a file

mkdir "Hello world" --creates a dir

mkdir -p nee/folder/subfolder -- To create directory under specified path

rmdir -- empty directory

rm -r -- to remove directory that has files

rm -ri folder -- interactive

To edit a file use nano or vi editor:

NANO:

nano filename -- brings you to editor

^ ctrl

M - alt

FIND:

find -name "*.Txt"

find -iname "*.TXT"

find -type f --file

find -type d --dir

find -maxdepth 2 --levels to search

-i -- case insensitive

Viewing files: cat file.txt

tac ----- reverse order vertically

rev ------ reverse horizontally

less file.txt -----when file size is big

head -n 20 test.txt -----first 20 lines

tail -n 20 -----last 20 lines

Sorting:

sort test.txt

sort -n test.txt ------> for numbers

sort -r -----> for reverse order

sort -u -----> for unique list

ARCHIVING-COMPRESSING:

It involves two steps:

1.creating tar balls : tar -cvf tarballname file1.txt file2.txt

C- creating tar V - verbose F ----file

Extracting ----x

tar -xvf tarballname

2.zip tarball using gzip or bzip2

gzip name.tar --> this will give --> name.tar.gz

gunzip name.tar.gz

creating Zip file:

zip name.zip file1 file 2 Unzip name.zip

To make file executable:

chmod +x file.txt

CRONTAB: To auto schedule jobs/commands

crontab -e ------- take u to crontab,where you can view cronjobs and can add new cron jobs

To find about the machine like Version, flavor:

uname -o Uname -r hostnamectl cat /etc/os-release

Installation and Removal

rpm -i --install (install new RPM; error if already installed) rpm -U --upgrade (delete existing RPM, if any; install new) rpm -F --freshen (update RPM only if package already installed) rpm -e --erase (remove, delete, expunge)

PACKAGE rpm -q [packages] [information] rpm -qa (all installed packages) rpm -q package_name rpm -qf (filename) rpm -qp (package filename) rpm -qa | grep foo

Tee

ls -l | tee new.txt | cat > t.txt

Tee command is literally a "T"

COMMAND flows from left to right

It will spit out the result of command in new.txt

File Permissions

Owner : Group : Others

Read - 4

Write - 2

Execute - 1 

       ls test.txt shows 10 indexs -rw-rw-r--

1st index -> Indicates file if it is a Directory it will show as d

2nd,3rd,4th -> Indicates Owner has read,write,execute permission

5th,6th,7th -> Indicates Group has read,write,execute permission

8th,9th,10th -> Indicates Others has read,write,execute permission