SlideShare a Scribd company logo
1 of 48
Download to read offline
Linux Basics
Linux Command Line Syntax
Command-Name {Options} {Inputs}
Options:
- <Single Character>
-- <Single Word>
Standard option to all the commands is --help
Example:
uname --help
ls –l –d /opt
Command
Option
Input
• Unlike windows Linux Commands are case-sensitive.
• You can get the help of any command by using man pages.
• Linux is more command line friendly than UI tools.
Linux Commands – System Information
• To check whether the machine is a 32bit or 64bit we can use the following
command.
•
uname –i
• On the output if it shows i386/i586/i686 then it is 32bit
• On the output if it shows as x86_64 then it is 64bit.
Linux Operating System - Architecture
Hardware
Software Utilities
Linux / Kernel
Users
Operating
System
• Linux is not an operating system and it is a code which drives the hardware.
• Vendors like RedHat pull the Linux code and embed that with software’s and
ships that as operating system.
Linux Commands – Operating & Hardware Info
• To check the vendor of operating system.
cat /etc/*release
• To check the CPU information.
cat /proc/cpuinfo
• To check the memory information.
cat /proc/meminfo
• To check the disk information
sudo fdisk -l
• To become more professional way of using command line you need to have lot of
hands on on CLI shortcuts. Following is one of the reference link for such
shortcuts.
https://github.com/fliptheweb/bash-shortcuts-cheat-sheet
• You can pick any link of your choice in google to get shortcuts.
Command Prompts
• Going forward we may need to perform some admin activities as well. In such
cases we need to understand the prompt for executing commands..
• Command prompt can help in determining whether you are a root (admin) user
or a normal user.
$ - Prompt denotes you are normal user
# - Prompt denotes you are root user
Username
currently
logged in
Hostname of server
• In companies we usually login with our account as normal user, but we can gain
the root access to the system using sudo command which we will discuss
that further.
Linux Commands – Listing files and Directories
• In the linux basic commands we prefer to start with ls command.
• ls command can fetch the files and directories in the current directory.
• ls -> Get list of files and directories, but it may not show hidden files.
• Hidden files in linux were created with .filename.
• ls –A -> Get list of hidden files and directories.
• ls –l -> Get list of files with long format, usually shows properties of a file.
• ls –Al -> We can combine multiple options as well, but depends on command.
Linux Commands – Creating files.
• We can create files in Linux in multiple ways/commands. As a basic we always
use touch command to create a file.
• Syntax: touch file-name -> Creates an empty file.
• Example: touch sample notes.txt lambda.py
• touch command can create multiple files as shown.
• In Linux we don’t have any file extensions. Extensions we may use it for our
understanding
Linux Commands – Remove files
• To remove files we have rm command, Also we can use unlink command which
performs the same action, yet we prefer mostly to use rm command.
• Syntax: rm file-name
• Example: rm sample
• Some times it may ask for a prompt (yes/no) to remove the files which
may require to parse –f option to not prompt it.
Linux Commands – Copy files
• To copy a file we have cp command. Alternatively we have rsync command as
well but mostly we prefer to use cp command in general.
• Syntax: cp source-file destination-file
• Example: cp file1.txt file2.txt
• If the destination file already exists then it will overwrite the file and in few
cases it may warn you to overwrite the file or not.
•
Linux Commands – Renaming files
• To rename a file we use mv command
• Syntax: mv source-file destination-file
• Example: mv file1.txt file2.txt
• If the destination file already exists then it will overwrite the file and in few
cases it may warn you to overwrite the file or not.
• mv command intention is to move the file from one location to another location
and yet it is also mainly used to rename the files.
Linux Basics :: Directory Structure
Root Directory
(/)
This path can be denoted as
/usr/bin
Linux Commands – Present Working Directory
• To Check in which directory you are in then pwd command can help you on
that.
• It is always important to observe the directory you are in before executing the
command, because in some cases if you try to execute some command and which
you lead to loss of data if you execute commands in wrong location.
Linux Commands – Change Directory
• To change your working directory from one location to another we use cd
command.
• Syntax: cd <directory>
• Example : cd /bin <- You will switch to /bin directory.
• cd <- Simple cd command will take you to user home directory.
• cd - <- A hyphen symbol after cd command can take you to previous working
directory.
• cd .. <- Double dot denotes parent directory and it can take you to parent
directory of existing directory.
Linux Basics– Single dot(.) and double dot(..)
• Dots in Linux denote the present working directory. You can use that in the
commands which we have used so far.
• cp /opt/file1.txt .
• Here dot denotes to copy the file in this location without specifying any
filename or path.
• Double dot denotes the parent directory which we can understand that after
discussing about directories and their management.
Linux Commands – Create Directory
• To create a directory you can use mkdir command.
• Syntax: mkdir <directory>
• Example : mkdir demo <- It will create an directory.
• mkdir –p demo/new/item1 <- -p Option will be used to create a
directory recursively even if the parent directory is missing.
• mkdir dir1 dir2 - <- Command mkdir can create multiple directories
also at the same time.
Linux Commands – Remove Directory
• Removing directory commands needed to be picked based on requirement.
• To remove empty directories we use rmdir command.
• To remove directories recursively we use rm command
• Syntax: rmdir <empty-directory> or rm –r <directory>
• rmdir demo <- It removes the directory only if demo directory is empty
• rm –r dir1 dir2 - <- Command rm –r can delete multiple directories
also at the same time and it will remove all the files recursively.
Linux Commands – Copy Directory
• Copying directories can be done with cp command.
• While copying the directories we need to mention –r option to enable that we
are copying directories.
• Syntax: cp –r dir1 dir2 <- It copies dir1 to dir2 and all the contents of
dir1 will be copied to dir2 as well.
• If dir2 already exists then dir1 will be copied inside dir2
Linux Commands – Moving Directory
• Moving directories or renaming directories can be done with mv command.
• Syntax: mv source destination <- Depends on the situation it will
rename or move.
• If destination does not exists then it renames the directory.
• If destination exists:
• Destination is a file - Then that is a invalid operation.
• Destination is a directory – Then the source will be moved into destination
directory.
Linux Commands – Concatenate a file
• In view the complete content of a file then we will concatenate (cat) the file.
• Syntax: cat <file-name> -> It shows complete content of a file
• For demo purpose I would copy one system file and demonstrate using it.
• $ cp /etc/passwd .
• $ cat passwd <- Shows the complete content of a file
• $ cat –n passwd <- Shows the content with line numbers added on
output.
• $ tac passwd <- It will print the lines in reverse order mean last line in
first and first line at last.
• In most cases you don’t need the complete content, Hence we need filters.
Linux Commands – head command filter
• In most cases we may not the complete file content, So in those cases we need
some filters to get only content which is needed.
• Command head will get the top 10 lines and it can be changed as per our need.
• Syntax: head <file-name> <- Prints top 10 lines by default
• head –n 5 passwd <- Print top 5 lines
Linux Commands – tail command filter
• Head command can give the top lines however tail command will print lines of
a file from ending
• Command tail will get the last 10 lines and it can be changed as per our
need.
• Syntax: tail<file-name> <- Prints last 10 lines by default
• tail –n 5 passwd <- Print last 5 lines
• tail –f file-name <- -f option is used to follow the file and all the
contents which are getting added to the file will be displayed on the screen.
• To come out of tail –f you can press CTRL +C on terminal.
Linux Commands – grep command filter
• In case if we need only the lines which are having a particular word or a string
then grep command is the right command. It searches a word and prints only
those lines.
• Syntax: grep word file-name
• Example : grep root passwd <- It fethes all the lines having a word root
in passwd file.
Linux Commands – awk command filter
• Some cases the content need to be filtered based on columns. Such cases we
can approach either cut command or awk command. I would prefer to use awk
command over cut command.
• Syntax: awk –F ‘Delimiter’ ‘{print $Column-Number}’
file
• Example:
• awk –F : ‘{print $1}’ passwd
• awk -F : ‘{print $1,$2}’ passwd
• $NF is used to print nth field which is last one in case if you don’t know how
many number of fields exist in that file.
Linux Commands – File Editors
• RedHat Linux has so many utilities that edits the file and its content. Utilities
like vi, vim, gedit, nano are widely used and that depends on user
choice. But vi is widely used and vim is a enhanced version of vi. So will
discuss about vim in our sessions.
• Editor vim is not available by default in CentOS 7 operating system, So lets
install it before using it.
• $ sudo yum install vim -y
Linux Commands – vim Editor
VI Editor – ESC MODE
• / -> Search a word .. Ex: /root
• yy -> Yank (Copy) a single line
• nyy -> Yank n lines
• p / np -> Paste copied line / Paste n times
• dd / ndd -> CutDelete a line / n lines
• u – Undo Changes like CTRL+z in windows
VI Editor – COLON MODE
• :/word -> Search a word
• :w -> Save the changes
• :q -> Come out of editor after saving changes
• :q! -> Come out of editor without saving changes
• :wq -> Save and Quit
• :%s/word1/word2/. -> Search word1 and replace with
word2 in the file
• %s/word1/word2/g -> Considers global replacement on line
• %s/word1/word2/i -> Considers case insensitive of word1
while searching and replaces with word2
VI Editor – INSERT MODE
• Insert mode is to add / remove content like your
normal editor in windows.
Linux Commands – Finding Files :: find command
• Most of the times you login to a system where you don’t know where the files
which you are looking for and definitely need to find those files to do your job.
• Finding the files can be done with multiple utilities, yet find command is a
very powerful utility available in most of Linux distributions.
• Syntax: find <location-to-find> <search-criteria>
• Examples:
• find / -name sample.conf -> Find all the system and get file named sample.conf
• find /boot –type d -> Find all directories in /boot and list
• find / -iname “*.conf” –type f -> Find in all system and get all the
file names ending with .conf.
Linux Commands – Finding Files :: locate command
• In RedHat Linux distribution we have another command which helps in finding
the file location.
• Command locate also can fetch you the files which is from the indexed index
but not by looking the actual file system.
• By default this package is not available, Install it and then update index.
• sudo yum install mlocate –y
• sudo updatedb
• After updating index you can find the files. (Indexing happens in OS for every
24 hours)
• locate “*.conf”
Linux Commands – Command line Browser
• Most of the time you need to browse URLs and fetch that content over the
command line. Some times we need some partial information of that URL else we
need complete information of that URL.
• Command curl is available to browse the content over the command line
• Syntax: curl URL
• Some cases that URL might be some downloadable software and in those cases
• Syntax: curl URL –o file-name-to-save-download
Linux Commands – Downloading files
• Most of the times we just need to download the software of different tools
which we work on. To just download the software we can use wget command.
• Command wget just downloads the file in the location which you are in, Else
you can provide a custom location as well.
• Syntax: wget <URL>. -> Downloads in current directory
• Syntax: wget –O /opt/<file-name> <URL> -> Downloads the file in
given path and name
Linux Commands – Extract tar archives
• Most of the times download the software from internet of different tools which
we use. And some of those tools are archives which are compressed either in
.zip or .tar format. In order to extract tar files then we use tar command
and for .zip files it is unzip command.
• Command tar can be used for both extraction and creation of archives.
• To extract the tar archives we use –x option.
• Syntax: tar –xf <file>.tar.gz -> Extracts the file
• Usually we find tar files with compression applied are .gz and .bz2. Command
tar can understand what compression was applied and it extracts automatically
with out even specifying any option.
Linux Commands – Pipes
• Pipes are used to send one command output as input to another command.
• Pipes converts STDOUT as STDIN, And commands those which accepts STDIN can
only be used with pipe.
• For an example rm command will not accept STDIN, Hence cannot be used with
pipes.
Linux Commands – Process Management
• Every command we execute in Linux will create a process and every process will
get an associated ID which we generally call it as PID and it is unique in the OS
which is taken care by Kernel.
• As part of our job we will manage such processes run inside server. In order to
manage those process we need the information about the process. Command ps
can help us in getting required/all process running inside the OS.
• ps -> List the process running in current session
• ps –u -> List process running by the user you logged in.
• ps –e -> Get all process running inside OS
• ps –ef -> All process listed out with more detailed way.
Linux Commands – Process Management
• We do need to manage these process, Some cases we need to stop/kill them.
• To kill any process under Linux OS can use kill command.
• Command kill will be used to kill the process with PID as input provided.
• In general we use two type of killing a process by using a signal number 15 and
9, 15 is default signal and we no need to specify in particular.
• kill PID -> Kill the process of given PID with 15 sig
• kill -9 PID -> Kill the process of given PID with 9
signal.
• 15 signal is graceful kill and where as 9 is forceful kill of a process.
Linux Commands – Administration
• In RedHat/CentOS Linux, All admin activities cannot be performed by normal
user. We need to be a root user to perform any activities.
• To perform those admin activities we use sudo command to gain the root
access and perform those admin commands.
• To any admin command we can prefix sudo command to gain root privilege.
• As we are using cloud based servers we usually login with normal user like
centos and such default users will have complete sudo access by default.
• In companies we usually will have individual accounts and we can perform the
admin activities which are allowed using sudo access.
Linux Administration – User Management
• In RedHat Linux family, User cannot be added with out a group. So we need a
group in order to add a user. User can be part of one more group but primarily
should be associated with one group.
• sudo groupadd devops
• To check whether the group added or not by using cat /etc/group | grep
devops
• We can now add a user to devops group.
• sudo useradd –g devops raju
• To verify the user which was added id raju
Linux Administration – User Management
• To add a user to multiple groups.
• usermod –a –G bin raju
• To set a password to the user (Clouds will not use password by default)
• passwd raju
• You can switch user from one user to another user using.
• su - raju
• To again another user with out password using sudo
• sudo su - raju
Linux Administration – SUDO configuration
• Sudo configuration allows users to execute sudo commands which are defined
here. To add a user to multiple groups.
• sudo visudo
Linux Administration – Package Management
• RedHat Linux uses rpm for packaging. Such packages can be downloaded and
installed using yum command which uses rpm command in backend.
• YUM has capability to download and install the packages from different sources
which are defined under /etc/yum.repos.d/*.repo
• sudo yum list / sudo yum list all
• sudo yum list installed
• sudo yum list available
• sudo yum install httpd –y
• sudo yum remove httpd –y
• sudo yum update httpd –y
Linux Administration – Service Management
• RedHat Linux 7 uses systemctl command to manage the services, Earlier till 6
version we use to use service command.
• To list all services which are active.
• sudo systemctl list-units -t service
• TO start/stop/restart a service.
• sudo systemctl start httpd
• sudo systemctl stop httpd
• sudo systemctl restart httpd
• To check the status of httpd.
• sudo systemctl status httpd
• To start the service at the time of reboot automatically then
• sudo systemctl enable httpd
sudo systemctl disable httpd
LinuxCommands (1).pdf

More Related Content

Similar to LinuxCommands (1).pdf

Similar to LinuxCommands (1).pdf (20)

PowerPoint_merge.ppt on unix programming
PowerPoint_merge.ppt on unix programmingPowerPoint_merge.ppt on unix programming
PowerPoint_merge.ppt on unix programming
 
LINUX_admin_commands.pptx
LINUX_admin_commands.pptxLINUX_admin_commands.pptx
LINUX_admin_commands.pptx
 
Linux Fundamentals
Linux FundamentalsLinux Fundamentals
Linux Fundamentals
 
redhat_by_Cbitss.ppt
redhat_by_Cbitss.pptredhat_by_Cbitss.ppt
redhat_by_Cbitss.ppt
 
Linuxnishustud
LinuxnishustudLinuxnishustud
Linuxnishustud
 
UNIX/Linux training
UNIX/Linux trainingUNIX/Linux training
UNIX/Linux training
 
Basic
BasicBasic
Basic
 
Linux: Everyting-as-a-service
Linux: Everyting-as-a-serviceLinux: Everyting-as-a-service
Linux: Everyting-as-a-service
 
ITCP PRACTICAL-1.pptx
ITCP PRACTICAL-1.pptxITCP PRACTICAL-1.pptx
ITCP PRACTICAL-1.pptx
 
Unix _linux_fundamentals_for_hpc-_b
Unix  _linux_fundamentals_for_hpc-_bUnix  _linux_fundamentals_for_hpc-_b
Unix _linux_fundamentals_for_hpc-_b
 
3. intro
3. intro3. intro
3. intro
 
cisco
ciscocisco
cisco
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unix
 
Ericas-Linux-Plus-Study-Guide
Ericas-Linux-Plus-Study-GuideEricas-Linux-Plus-Study-Guide
Ericas-Linux-Plus-Study-Guide
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentation
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 
Unix_QT.ppsx
Unix_QT.ppsxUnix_QT.ppsx
Unix_QT.ppsx
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
 
Linux
LinuxLinux
Linux
 

Recently uploaded

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 

Recently uploaded (20)

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 

LinuxCommands (1).pdf

  • 2. Linux Command Line Syntax Command-Name {Options} {Inputs} Options: - <Single Character> -- <Single Word> Standard option to all the commands is --help Example: uname --help ls –l –d /opt Command Option Input
  • 3. • Unlike windows Linux Commands are case-sensitive. • You can get the help of any command by using man pages. • Linux is more command line friendly than UI tools.
  • 4. Linux Commands – System Information • To check whether the machine is a 32bit or 64bit we can use the following command. • uname –i • On the output if it shows i386/i586/i686 then it is 32bit • On the output if it shows as x86_64 then it is 64bit.
  • 5. Linux Operating System - Architecture Hardware Software Utilities Linux / Kernel Users Operating System
  • 6. • Linux is not an operating system and it is a code which drives the hardware. • Vendors like RedHat pull the Linux code and embed that with software’s and ships that as operating system.
  • 7. Linux Commands – Operating & Hardware Info • To check the vendor of operating system. cat /etc/*release • To check the CPU information. cat /proc/cpuinfo • To check the memory information. cat /proc/meminfo • To check the disk information sudo fdisk -l
  • 8. • To become more professional way of using command line you need to have lot of hands on on CLI shortcuts. Following is one of the reference link for such shortcuts. https://github.com/fliptheweb/bash-shortcuts-cheat-sheet • You can pick any link of your choice in google to get shortcuts.
  • 9. Command Prompts • Going forward we may need to perform some admin activities as well. In such cases we need to understand the prompt for executing commands.. • Command prompt can help in determining whether you are a root (admin) user or a normal user. $ - Prompt denotes you are normal user # - Prompt denotes you are root user Username currently logged in Hostname of server
  • 10. • In companies we usually login with our account as normal user, but we can gain the root access to the system using sudo command which we will discuss that further.
  • 11. Linux Commands – Listing files and Directories • In the linux basic commands we prefer to start with ls command. • ls command can fetch the files and directories in the current directory. • ls -> Get list of files and directories, but it may not show hidden files. • Hidden files in linux were created with .filename. • ls –A -> Get list of hidden files and directories. • ls –l -> Get list of files with long format, usually shows properties of a file. • ls –Al -> We can combine multiple options as well, but depends on command.
  • 12. Linux Commands – Creating files. • We can create files in Linux in multiple ways/commands. As a basic we always use touch command to create a file. • Syntax: touch file-name -> Creates an empty file. • Example: touch sample notes.txt lambda.py • touch command can create multiple files as shown. • In Linux we don’t have any file extensions. Extensions we may use it for our understanding
  • 13. Linux Commands – Remove files • To remove files we have rm command, Also we can use unlink command which performs the same action, yet we prefer mostly to use rm command. • Syntax: rm file-name • Example: rm sample • Some times it may ask for a prompt (yes/no) to remove the files which may require to parse –f option to not prompt it.
  • 14. Linux Commands – Copy files • To copy a file we have cp command. Alternatively we have rsync command as well but mostly we prefer to use cp command in general. • Syntax: cp source-file destination-file • Example: cp file1.txt file2.txt • If the destination file already exists then it will overwrite the file and in few cases it may warn you to overwrite the file or not. •
  • 15. Linux Commands – Renaming files • To rename a file we use mv command • Syntax: mv source-file destination-file • Example: mv file1.txt file2.txt • If the destination file already exists then it will overwrite the file and in few cases it may warn you to overwrite the file or not. • mv command intention is to move the file from one location to another location and yet it is also mainly used to rename the files.
  • 16. Linux Basics :: Directory Structure Root Directory (/) This path can be denoted as /usr/bin
  • 17. Linux Commands – Present Working Directory • To Check in which directory you are in then pwd command can help you on that. • It is always important to observe the directory you are in before executing the command, because in some cases if you try to execute some command and which you lead to loss of data if you execute commands in wrong location.
  • 18. Linux Commands – Change Directory • To change your working directory from one location to another we use cd command. • Syntax: cd <directory> • Example : cd /bin <- You will switch to /bin directory. • cd <- Simple cd command will take you to user home directory. • cd - <- A hyphen symbol after cd command can take you to previous working directory. • cd .. <- Double dot denotes parent directory and it can take you to parent directory of existing directory.
  • 19. Linux Basics– Single dot(.) and double dot(..) • Dots in Linux denote the present working directory. You can use that in the commands which we have used so far. • cp /opt/file1.txt . • Here dot denotes to copy the file in this location without specifying any filename or path. • Double dot denotes the parent directory which we can understand that after discussing about directories and their management.
  • 20. Linux Commands – Create Directory • To create a directory you can use mkdir command. • Syntax: mkdir <directory> • Example : mkdir demo <- It will create an directory. • mkdir –p demo/new/item1 <- -p Option will be used to create a directory recursively even if the parent directory is missing. • mkdir dir1 dir2 - <- Command mkdir can create multiple directories also at the same time.
  • 21. Linux Commands – Remove Directory • Removing directory commands needed to be picked based on requirement. • To remove empty directories we use rmdir command. • To remove directories recursively we use rm command • Syntax: rmdir <empty-directory> or rm –r <directory> • rmdir demo <- It removes the directory only if demo directory is empty • rm –r dir1 dir2 - <- Command rm –r can delete multiple directories also at the same time and it will remove all the files recursively.
  • 22. Linux Commands – Copy Directory • Copying directories can be done with cp command. • While copying the directories we need to mention –r option to enable that we are copying directories. • Syntax: cp –r dir1 dir2 <- It copies dir1 to dir2 and all the contents of dir1 will be copied to dir2 as well. • If dir2 already exists then dir1 will be copied inside dir2
  • 23. Linux Commands – Moving Directory • Moving directories or renaming directories can be done with mv command. • Syntax: mv source destination <- Depends on the situation it will rename or move. • If destination does not exists then it renames the directory. • If destination exists: • Destination is a file - Then that is a invalid operation. • Destination is a directory – Then the source will be moved into destination directory.
  • 24. Linux Commands – Concatenate a file • In view the complete content of a file then we will concatenate (cat) the file. • Syntax: cat <file-name> -> It shows complete content of a file • For demo purpose I would copy one system file and demonstrate using it. • $ cp /etc/passwd . • $ cat passwd <- Shows the complete content of a file • $ cat –n passwd <- Shows the content with line numbers added on output. • $ tac passwd <- It will print the lines in reverse order mean last line in first and first line at last. • In most cases you don’t need the complete content, Hence we need filters.
  • 25. Linux Commands – head command filter • In most cases we may not the complete file content, So in those cases we need some filters to get only content which is needed. • Command head will get the top 10 lines and it can be changed as per our need. • Syntax: head <file-name> <- Prints top 10 lines by default • head –n 5 passwd <- Print top 5 lines
  • 26. Linux Commands – tail command filter • Head command can give the top lines however tail command will print lines of a file from ending • Command tail will get the last 10 lines and it can be changed as per our need. • Syntax: tail<file-name> <- Prints last 10 lines by default • tail –n 5 passwd <- Print last 5 lines • tail –f file-name <- -f option is used to follow the file and all the contents which are getting added to the file will be displayed on the screen. • To come out of tail –f you can press CTRL +C on terminal.
  • 27. Linux Commands – grep command filter • In case if we need only the lines which are having a particular word or a string then grep command is the right command. It searches a word and prints only those lines. • Syntax: grep word file-name • Example : grep root passwd <- It fethes all the lines having a word root in passwd file.
  • 28. Linux Commands – awk command filter • Some cases the content need to be filtered based on columns. Such cases we can approach either cut command or awk command. I would prefer to use awk command over cut command. • Syntax: awk –F ‘Delimiter’ ‘{print $Column-Number}’ file • Example: • awk –F : ‘{print $1}’ passwd • awk -F : ‘{print $1,$2}’ passwd • $NF is used to print nth field which is last one in case if you don’t know how many number of fields exist in that file.
  • 29. Linux Commands – File Editors • RedHat Linux has so many utilities that edits the file and its content. Utilities like vi, vim, gedit, nano are widely used and that depends on user choice. But vi is widely used and vim is a enhanced version of vi. So will discuss about vim in our sessions. • Editor vim is not available by default in CentOS 7 operating system, So lets install it before using it. • $ sudo yum install vim -y
  • 30. Linux Commands – vim Editor
  • 31. VI Editor – ESC MODE • / -> Search a word .. Ex: /root • yy -> Yank (Copy) a single line • nyy -> Yank n lines • p / np -> Paste copied line / Paste n times • dd / ndd -> CutDelete a line / n lines • u – Undo Changes like CTRL+z in windows
  • 32. VI Editor – COLON MODE • :/word -> Search a word • :w -> Save the changes • :q -> Come out of editor after saving changes • :q! -> Come out of editor without saving changes • :wq -> Save and Quit • :%s/word1/word2/. -> Search word1 and replace with word2 in the file • %s/word1/word2/g -> Considers global replacement on line • %s/word1/word2/i -> Considers case insensitive of word1 while searching and replaces with word2
  • 33. VI Editor – INSERT MODE • Insert mode is to add / remove content like your normal editor in windows.
  • 34. Linux Commands – Finding Files :: find command • Most of the times you login to a system where you don’t know where the files which you are looking for and definitely need to find those files to do your job. • Finding the files can be done with multiple utilities, yet find command is a very powerful utility available in most of Linux distributions. • Syntax: find <location-to-find> <search-criteria> • Examples: • find / -name sample.conf -> Find all the system and get file named sample.conf • find /boot –type d -> Find all directories in /boot and list • find / -iname “*.conf” –type f -> Find in all system and get all the file names ending with .conf.
  • 35. Linux Commands – Finding Files :: locate command • In RedHat Linux distribution we have another command which helps in finding the file location. • Command locate also can fetch you the files which is from the indexed index but not by looking the actual file system. • By default this package is not available, Install it and then update index. • sudo yum install mlocate –y • sudo updatedb • After updating index you can find the files. (Indexing happens in OS for every 24 hours) • locate “*.conf”
  • 36. Linux Commands – Command line Browser • Most of the time you need to browse URLs and fetch that content over the command line. Some times we need some partial information of that URL else we need complete information of that URL. • Command curl is available to browse the content over the command line • Syntax: curl URL • Some cases that URL might be some downloadable software and in those cases • Syntax: curl URL –o file-name-to-save-download
  • 37. Linux Commands – Downloading files • Most of the times we just need to download the software of different tools which we work on. To just download the software we can use wget command. • Command wget just downloads the file in the location which you are in, Else you can provide a custom location as well. • Syntax: wget <URL>. -> Downloads in current directory • Syntax: wget –O /opt/<file-name> <URL> -> Downloads the file in given path and name
  • 38. Linux Commands – Extract tar archives • Most of the times download the software from internet of different tools which we use. And some of those tools are archives which are compressed either in .zip or .tar format. In order to extract tar files then we use tar command and for .zip files it is unzip command. • Command tar can be used for both extraction and creation of archives. • To extract the tar archives we use –x option. • Syntax: tar –xf <file>.tar.gz -> Extracts the file • Usually we find tar files with compression applied are .gz and .bz2. Command tar can understand what compression was applied and it extracts automatically with out even specifying any option.
  • 39. Linux Commands – Pipes • Pipes are used to send one command output as input to another command. • Pipes converts STDOUT as STDIN, And commands those which accepts STDIN can only be used with pipe. • For an example rm command will not accept STDIN, Hence cannot be used with pipes.
  • 40. Linux Commands – Process Management • Every command we execute in Linux will create a process and every process will get an associated ID which we generally call it as PID and it is unique in the OS which is taken care by Kernel. • As part of our job we will manage such processes run inside server. In order to manage those process we need the information about the process. Command ps can help us in getting required/all process running inside the OS. • ps -> List the process running in current session • ps –u -> List process running by the user you logged in. • ps –e -> Get all process running inside OS • ps –ef -> All process listed out with more detailed way.
  • 41. Linux Commands – Process Management • We do need to manage these process, Some cases we need to stop/kill them. • To kill any process under Linux OS can use kill command. • Command kill will be used to kill the process with PID as input provided. • In general we use two type of killing a process by using a signal number 15 and 9, 15 is default signal and we no need to specify in particular. • kill PID -> Kill the process of given PID with 15 sig • kill -9 PID -> Kill the process of given PID with 9 signal. • 15 signal is graceful kill and where as 9 is forceful kill of a process.
  • 42. Linux Commands – Administration • In RedHat/CentOS Linux, All admin activities cannot be performed by normal user. We need to be a root user to perform any activities. • To perform those admin activities we use sudo command to gain the root access and perform those admin commands. • To any admin command we can prefix sudo command to gain root privilege. • As we are using cloud based servers we usually login with normal user like centos and such default users will have complete sudo access by default. • In companies we usually will have individual accounts and we can perform the admin activities which are allowed using sudo access.
  • 43. Linux Administration – User Management • In RedHat Linux family, User cannot be added with out a group. So we need a group in order to add a user. User can be part of one more group but primarily should be associated with one group. • sudo groupadd devops • To check whether the group added or not by using cat /etc/group | grep devops • We can now add a user to devops group. • sudo useradd –g devops raju • To verify the user which was added id raju
  • 44. Linux Administration – User Management • To add a user to multiple groups. • usermod –a –G bin raju • To set a password to the user (Clouds will not use password by default) • passwd raju • You can switch user from one user to another user using. • su - raju • To again another user with out password using sudo • sudo su - raju
  • 45. Linux Administration – SUDO configuration • Sudo configuration allows users to execute sudo commands which are defined here. To add a user to multiple groups. • sudo visudo
  • 46. Linux Administration – Package Management • RedHat Linux uses rpm for packaging. Such packages can be downloaded and installed using yum command which uses rpm command in backend. • YUM has capability to download and install the packages from different sources which are defined under /etc/yum.repos.d/*.repo • sudo yum list / sudo yum list all • sudo yum list installed • sudo yum list available • sudo yum install httpd –y • sudo yum remove httpd –y • sudo yum update httpd –y
  • 47. Linux Administration – Service Management • RedHat Linux 7 uses systemctl command to manage the services, Earlier till 6 version we use to use service command. • To list all services which are active. • sudo systemctl list-units -t service • TO start/stop/restart a service. • sudo systemctl start httpd • sudo systemctl stop httpd • sudo systemctl restart httpd • To check the status of httpd. • sudo systemctl status httpd • To start the service at the time of reboot automatically then • sudo systemctl enable httpd sudo systemctl disable httpd