Linux🐧

·

8 min read

All of you maybe heard about Linux. Linux is an Open Source Operating System. It has majorly three Distributions.

  1. Debian Family System

    Ubuntu is an OS of Debian. Widely used in cloud deployments. GNOME-based OS."apt" package manager.

  2. Red Hat Family System

    Fedora is an OS of Red Hat. Widely used by enterprises."yum" package manager.

  3. Suse Family System

    openSUSE is an OS of Suse. Widely used in retail."zypper" package manager.

So now, Let's see Some Commands and their use cases.

when some commands you run and it shows 'permission denied' use 'sudo' at first

sudo-

  • means allows you to temporarily elevate your current user account to have root privileges
sudo useradd abhii #it lets you add a new user to the machine
#after this it asking for password
sudo passwd abhiii

sudo userdel Abhii #it deletes the user that you addSo now, Let's see Some Commands and their use cases.

GUI -CLI (vice versa)-

  • this command changes your GUI interface to a CLI interface.
sudo systemctl stop gdm
#or 
sudo telinit 3
  • This command changes your CLI interface to a GUI interface.
sudo systemctl start gdm
#or
sudo telinit 5
  • Linux is a multi-user OS to identify the current user
whoami

common commands-

cd . #present direcory
cd .. #parent directory #now you are one step back to the present directory
cd ~ #home directory
cd foldername #to go into that folder
cd / # going to the root directory
pwd #displays where are you
ls #listing the folder items
ls -l  #shows the file details rwx etc
ls -a #show all files includes hidden files
rm filename #to remove a file
head -5 #displays only first 5 lines of file
tail -5 #displays only last 5 lines of file
whereis python3 #it gives the path where's python exists
open . #it opens the current folder in GUI interface
clear #it clear all old commands that were shown screen
man command_name #it shows detail about that command -' man ls '
df #to check the disk space usage # 'df -h " also you can use
diff  file1.txt file2.txt #displays the difference b/w these two files
locate "*.txt" #searching the file in whole system & find ".txt" files
history #shows the all history of commands that you entered with s.no.
history |grep "ls" #shows the history of 'ls' command how many times you have entered it also displayed

touch-

  • used to make an empty file
touch newfile.txt #newfile.txt is being created by this cmd
  • By 'touch -t' you can change the date and time of the file when it was created
touch -t 202306081051 newfile.txt #now its current date and time changed to this one

mkdir and rmdir-

  • mkdir - make a directory/folder
mkdir abhiDevOps #this will created a folder name abhiDevOps
mkdir /usr/abhiDevOps #this will create same folder but under 'usr' directory
  • rmdir - remove an empty directory/folder
rmdir random #this will remove the random folder if there's no content inside it.
#if content present in random then it will not be deleted by rmdir
  • rm -rf

forcefully removes the directory

rm -rf random
  • rm -i

Interactively remove a directory/file

rm -i abhi.txt #now it asks before delete the file (Y/N-input)

pipes-

Linux combines several commands into one

mkdir command1|mkdir cmd2|mkdir cmd3 #now 3 directories creates by single cmd

dpkg-

  • displays the packages available for your system
dpkg --list

install and remove a package-

sudo apt-get install wget2-dev #here wget2-dev is a software which can be downloaded by this command
sudo apt-get remove wget2 #to remove the package

managing jobs-

ps #provides info about the currently running processes
ps -ef #provides all the processesin the screen with details

scheduling commands-

  • by this
at 03:30
#some warning stuff  
at>echo first >>this file
at>echo second >>that file
at><EOT> 
#(ctrl + d)

text editors-

  • these are the text editors which are pre-installed with Linux shell
#text editors
nano
gedit
vi
nano file1.txt
#new window will open its basically a text editor called nano
write something inside this 
ctrl + X (for exit)
for saving prompt will open .(y/n)exit
vi test2
#type i to write into the file
write here
#'esc' to exit from insert mode
#:wq -to save the file
#:q! -quit without saving the file

Creating files -

  • 'echo ' is used to create a file and by the use of '>' arrows we can write inside the file as well. You can use only two arrows ('>>'). This means the next line.
echo "hello abhii" > file.txt #means create a file  'file.txt' and enter txt 'hello abhii'
echo this text will be found in first line > myfile
echo this will be in second  because of 2 arrow >> myfile #this will be added in next line
echo this will in 3rd and so on by this arrow >> myfile #this will after upper 
echo "devOps with Abhii" > file.txt #only this 'devOps with Abhii' remains in file other all content will be deleted
  • 'cat' is used to display the content inside the file, But by the use of 'cat' you can create the files and also by this you can write inside the file

  • cat -concatenate

cat filename.txt |tr a-z A-Z
#means that translate(tr) small letters to capital letters same as vice versa 
cat anyfile.txt 
#it displays the content inside this file
cat <<EOF> myfile.txt
>by ths
>we can 
>write inside the file
>EOF
#by this command you can write inside the file'cat' is used to display, But by the use of  'cat' you can  creating the files and also by this you can writing inside the file

adding and removing users-

  • only root users can add & remove users and groups.
sudo useradd anyusernamehere
#for adding the user

sudo userdel anyusernamehere
#for removing the user

file ownership-

  • change ownership

  • change group

  • change permissions

sudo chown root filename 
# To change the Owner of the file /now filename is under root user instead of user
sudo chgrp  nameofgroup nameofdirectory
 # to change a directory group ownership, place the name of group and then place name of the directory in the command:
chmod 777 filename.txt
#used to modify the permission so that it can grant or restrict access to directories and files.

chain commands-

  • run two commands at once
mkdir abhii \
>cat hello

copy/move-

  • cp used for copying files/directory
cp file1.txt copiedfile.txt
#this will creates a copy of file1.txt as copiedfile.txt
  • mv used for moving files/directory
mv oldfile.txt movedfile.txt
#means oldefile.txt has been moved to movedfile.txt
  • to check the disk space usage

permissions (rwx)-

  • shows that details about read write and execute for - user, group and others
ls -l filename.txt #shows the extra details like file for read write and execute
chmod 777 filename.txt #means rwx permissions allow for - user , group and other
sudo chown root filename.txt #now this file has root permissions
sudo chmod 700 filename.txt #now this file has only permissions for user.

find-

  • through this, you can find
find . -empty #shows the files that are empty
find . #means display all the dir/subdir. and files from current directory
find . -size +1k #means show all files in current directory that are more than 1kb
find . -perm 777 #find all the files that have all permissions(r,w,x,) for user,group and other
find . -type f -name "*.txt" -exec rm -rf #remove all the files that ends with .txt
!find #the last command that you entered displays

grep-

  • global regular expression print

  • allows us to search text in between the files and it is case sensitive

grep "abhii" names.txt
 #means if "abhii" text present in this file then it will point out that otherwise NULL
grep -i "abhii" names.txt
 #means now it is not case sensitive

sort-

sort filename.txt
 #sorted the content in ascending order 
sort -r filename.txt
 #by this content inside the file sorted in reverse order
sort -n filename.txt
 #if numbers present inside the file all sorted in 0-100 format

zip/unzip-

zip file1.zip file2.txt 
#by this 'file1' will be zipped and inside this file 'file2' content present
zip file3.zip file1.txt file2.txt
 #it make a 'file3' and inside this 'file1'+'file2' content present as format of zip
unzip file3.zip 
#this will unzip your file

networking commands-

nslookup google.com
 #shows  the networking details like server ,address
route 
#displays and manipulates the routing table existing for your system.

extra commands-

#we can add comment in the bash by typing '#' and only single line comment present in bash
#run multiple commands at once by using ';'
git add.;git commit -m "message";git push origin main 
ping google.com #shows us the connectivity status
wget https://google.com #downloads a file saved as index.html
wget -o myfile.pdf https://google.com #downloads a file & put all that data in myfile.pdf 
top #displays app and their details that are running
kill 457 #here 457 is process id by this you stop a particular application
hostname -i #gives us our ip address
sudo shutdown now #by this command you can shutdown your machine from command 
code . #open code editor 'vs code' by this in current directory
exit  #get out of the terminal

working with operators-

ping google.com & ping facebook.com #both runs together
echo "Hello" && echo "Bye" #only when first completed runs second "this is 'and' operator
echo "first" || echo "second" #'or' operator only one command will be executed
rm -rf  !(filename that you dont want to remove) #other all files will deleted from current directory
echo "Hey"  && echo "kaise ho " ; echo " i am good bro" #this is combined operator

BOOM 💥💥💥!!! You did it !!!!

Any type of feedback will be appreciated.

These are the basic commands of Linux.

Yeh, That's it, for this time.

Did you find this article valuable?

Support Abhishek by becoming a sponsor. Any amount is appreciated!