SlideShare a Scribd company logo
1 of 12
Download to read offline
GGSIPU-LUG
(WELCOME BACK!)

GETTING STARTED WITH THE LINUX SHELL
WHAT’S THE SHELL?
●

The shell (‘command line’) is a program that takes commands from you
and gives them to the OS to perform.

●

Before GUIs came around, the shell was the only way to interact with the
OS.

●

Even though GUIs are common today, it’s important to know how to use
the shell if you want to use the full power of Linux

●

Many different shell programs exist, but the most common one is called
bash - short for Bourne Again SHell (since it was written by Steve Bourne).
WHY USE A SHELL?
●

GUIs are good at a lot of things, but they’re not good at everything.

●

Using the shell can simplify your work and help you automate your tasks.
Moreover, there are some things you just can’t do with a GUI.

●

Here’s a little shell command that outputs the top ten largest files on your
hard drive to a file called ‘diskuse.txt’
du -h | sort -h | tail > diskuse.txt

●

Doing that on the GUI requires a specialized program written in a hundred
or so lines of code.
SHELL BASICS
●

You can access a shell on pretty much any Linux system by hitting Ctrl + Alt
+ F1 - F6.

●

Each of these key combinations produces a ‘new’ terminal - a bit like
having six different screens, of which you can see one at a time.

●

Once on a shell, you may get a prompt for a login and a password. Enter
that, and you’ll get something like this

●

Let’s take a closer look here.
SHELL BASICS
The text before the blinking cursor here is what we call a ‘prompt’, and it
provides information about the computer you’re working on. The prompt here is
puranjay@Slack:~$

There are four parts to this:
puranjay

is my username on the computer

@Slack

is the hostname (the ‘name’) of the computer

~

(the part after the :) means that I’m currently in my home directory

$

means that I’m a normal user (not root)
THREE VITAL COMMANDS
which shows you which directory you are currently working in

●

pwd ,

●

ls,

which shows you the contents of the current directory

●

cd,

which allows you to change your directory
COMPILING C/C++ PROGRAMS
●

Linux comes with a great C language compiler called gcc. Generally, it’s
pre-installed, but on some Ubuntu boxes, it’s not. If you’re using one of
those boxes, you can install it from the internet by typing this in the shell:
sudo aptitude install build-essential

●

Once you have gcc up and running, you can use it to compile C programs.
I’ve written a very basic program here (in notepad) as an example, and
saved it as helloworld.c
OUR EXAMPLE C PROGRAM
/* Small C Program to demonstrate the use of gcc */
#include <stdio.h>
int main()
{
printf (“Hello, world.n”);
return 0;
}
/* End program*/

I’ve gone ahead and saved this program as helloworld.c in the /home/puranjay/Demo
folder.
OUR EXAMPLE C PROGRAM
Before we can compile our program, we have to find the folder it’s in.
First step : Find out where we are.

A pwd command results in ‘/home/puranjay’. Now, I stored our program in the folder
/home/puranjay/Demo’, so let’s try to get there.

I’ve done cd Demo to change my directory to ‘Demo’, and then did a pwd, which confirms that I’m now
in the right directory /home/puranjay/Demo
OUR EXAMPLE C PROGRAM
Just for fun, let’s check out the contents of our current directory, by doing an ls command.

The ls command shows that there are four objects here. The first three, with a / in front of their name
are directories (folders), and our shell has highlighted them in blue. Next to the directories, sure
enough, is our C file, helloworld.c
Now that we’re in the right folder, it’s time to start compiling.
USING GCC
●

gcc, like all compilers, is a complex piece of software in itself, consisting of
over 7 million lines of code. It has numerous options for code optimization,
error reporting, permissiveness and so forth.

●

Since our program is a simple one, we needn’t be concerned with all the
options. All we need is a simple command.

●

Our command is gcc helloworld.c -o output
The part right after gcc is our filename, helloworld.c .After providing the
filename, we’ve added -o ouput which tells the compiler to make an
executable output file called output
USING GCC
Another ls command reveals that the file output has now been created. It is
marked with a * by our shell, to show that it is an executable file - it can be run.

To run it, we’re just going to type its name in the shell.

And there you go! Our program runs just as expected, displaying ‘Hello, world.’
on the screen.

More Related Content

What's hot

Module 02 Using Linux Command Shell
Module 02 Using Linux Command ShellModule 02 Using Linux Command Shell
Module 02 Using Linux Command ShellTushar B Kute
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scriptingVIKAS TIWARI
 
Docker and plone
Docker and ploneDocker and plone
Docker and ploneAlin Voinea
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell ScriptingMustafa Qasim
 
Alias as usual
Alias as usualAlias as usual
Alias as usualTsungyu Yu
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Scriptstudent
 
Docker Cheatsheet_01
Docker Cheatsheet_01Docker Cheatsheet_01
Docker Cheatsheet_01Infralovers
 
Docker Ecosystem: Part III - Machine
Docker Ecosystem: Part III - MachineDocker Ecosystem: Part III - Machine
Docker Ecosystem: Part III - MachineMario IC
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in LinuxAnu Chaudhry
 
DevOps Series: Extending vagrant with Puppet for configuration management
DevOps Series: Extending vagrant with Puppet for configuration managementDevOps Series: Extending vagrant with Puppet for configuration management
DevOps Series: Extending vagrant with Puppet for configuration managementFelipe
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scriptingvceder
 
Generating keyboard in raspberry pi
Generating keyboard in raspberry piGenerating keyboard in raspberry pi
Generating keyboard in raspberry piPrabhanda Prabha
 
Basic command ppt
Basic command pptBasic command ppt
Basic command pptRohit Kumar
 

What's hot (20)

Docker Workshop
Docker WorkshopDocker Workshop
Docker Workshop
 
Shell script-sec
Shell script-secShell script-sec
Shell script-sec
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Module 02 Using Linux Command Shell
Module 02 Using Linux Command ShellModule 02 Using Linux Command Shell
Module 02 Using Linux Command Shell
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Docker and plone
Docker and ploneDocker and plone
Docker and plone
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
 
Scripting and the shell in LINUX
Scripting and the shell in LINUXScripting and the shell in LINUX
Scripting and the shell in LINUX
 
Alias as usual
Alias as usualAlias as usual
Alias as usual
 
Unix Shell Script
Unix Shell ScriptUnix Shell Script
Unix Shell Script
 
Docker Cheatsheet_01
Docker Cheatsheet_01Docker Cheatsheet_01
Docker Cheatsheet_01
 
Unix shell scripting tutorial
Unix shell scripting tutorialUnix shell scripting tutorial
Unix shell scripting tutorial
 
Basics of shell programming
Basics of shell programmingBasics of shell programming
Basics of shell programming
 
Docker Ecosystem: Part III - Machine
Docker Ecosystem: Part III - MachineDocker Ecosystem: Part III - Machine
Docker Ecosystem: Part III - Machine
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
 
DevOps Series: Extending vagrant with Puppet for configuration management
DevOps Series: Extending vagrant with Puppet for configuration managementDevOps Series: Extending vagrant with Puppet for configuration management
DevOps Series: Extending vagrant with Puppet for configuration management
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
 
Generating keyboard in raspberry pi
Generating keyboard in raspberry piGenerating keyboard in raspberry pi
Generating keyboard in raspberry pi
 
Basic command ppt
Basic command pptBasic command ppt
Basic command ppt
 
Docker
DockerDocker
Docker
 

Viewers also liked (9)

Data communcation
Data communcationData communcation
Data communcation
 
Transmission modes (simplex, duplex &amp; half duplex)
Transmission modes (simplex, duplex &amp; half duplex)Transmission modes (simplex, duplex &amp; half duplex)
Transmission modes (simplex, duplex &amp; half duplex)
 
Transmission of Digital Data(Data Communication) DC11
Transmission of Digital Data(Data Communication) DC11Transmission of Digital Data(Data Communication) DC11
Transmission of Digital Data(Data Communication) DC11
 
Modes of Communication
Modes of CommunicationModes of Communication
Modes of Communication
 
10.data transmission
10.data transmission10.data transmission
10.data transmission
 
Transmission modes
Transmission modesTransmission modes
Transmission modes
 
Modes of Transmission
Modes of TransmissionModes of Transmission
Modes of Transmission
 
Transmission modes
Transmission modesTransmission modes
Transmission modes
 
Modes and Media Communication.
Modes and Media Communication.Modes and Media Communication.
Modes and Media Communication.
 

Similar to Linux shell ggsipu-lug

Reverse Engineering in Linux - The tools showcase
Reverse Engineering in Linux - The tools showcaseReverse Engineering in Linux - The tools showcase
Reverse Engineering in Linux - The tools showcaseLevis Nickaster
 
Cross Platform Objective C Development Using Gn Ustep
Cross Platform Objective C Development Using Gn UstepCross Platform Objective C Development Using Gn Ustep
Cross Platform Objective C Development Using Gn Ustepwangii
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projectsMpho Mphego
 
C plus plus for hackers it security
C plus plus for hackers it securityC plus plus for hackers it security
C plus plus for hackers it securityCESAR A. RUIZ C
 
Introducing Yeoman 1.0 beta
Introducing Yeoman 1.0 betaIntroducing Yeoman 1.0 beta
Introducing Yeoman 1.0 betadigitalzombie
 
Process (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSProcess (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSHarrytoye2
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008guestd9065
 
UCL All of the Things (MeetBSD California 2014 Lightning Talk)
UCL All of the Things (MeetBSD California 2014 Lightning Talk)UCL All of the Things (MeetBSD California 2014 Lightning Talk)
UCL All of the Things (MeetBSD California 2014 Lightning Talk)iXsystems
 
01 linux-quick-start
01 linux-quick-start01 linux-quick-start
01 linux-quick-startNguyen Vinh
 
Deep dive - Concourse CI/CD and Pipelines
Deep dive  - Concourse CI/CD and PipelinesDeep dive  - Concourse CI/CD and Pipelines
Deep dive - Concourse CI/CD and PipelinesSyed Imam
 
OS Lab Manual.pdf
OS Lab Manual.pdfOS Lab Manual.pdf
OS Lab Manual.pdfQucHunh15
 
C-PROGRAMMING-LANGUAGE.pptx
C-PROGRAMMING-LANGUAGE.pptxC-PROGRAMMING-LANGUAGE.pptx
C-PROGRAMMING-LANGUAGE.pptxDhirendraShahi2
 
Installing Software, Part 3: Command Line
Installing Software, Part 3: Command LineInstalling Software, Part 3: Command Line
Installing Software, Part 3: Command LineKevin OBrien
 

Similar to Linux shell ggsipu-lug (20)

Reverse Engineering in Linux - The tools showcase
Reverse Engineering in Linux - The tools showcaseReverse Engineering in Linux - The tools showcase
Reverse Engineering in Linux - The tools showcase
 
Opensource Software usability
Opensource Software usabilityOpensource Software usability
Opensource Software usability
 
linux
linuxlinux
linux
 
Cross Platform Objective C Development Using Gn Ustep
Cross Platform Objective C Development Using Gn UstepCross Platform Objective C Development Using Gn Ustep
Cross Platform Objective C Development Using Gn Ustep
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
 
hw1a
hw1ahw1a
hw1a
 
hw1a
hw1ahw1a
hw1a
 
C plus plus for hackers it security
C plus plus for hackers it securityC plus plus for hackers it security
C plus plus for hackers it security
 
Introducing Yeoman 1.0 beta
Introducing Yeoman 1.0 betaIntroducing Yeoman 1.0 beta
Introducing Yeoman 1.0 beta
 
Process (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oSProcess (OS),GNU,Introduction to Linux oS
Process (OS),GNU,Introduction to Linux oS
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
UCL All of the Things (MeetBSD California 2014 Lightning Talk)
UCL All of the Things (MeetBSD California 2014 Lightning Talk)UCL All of the Things (MeetBSD California 2014 Lightning Talk)
UCL All of the Things (MeetBSD California 2014 Lightning Talk)
 
C
CC
C
 
01 linux-quick-start
01 linux-quick-start01 linux-quick-start
01 linux-quick-start
 
Deep dive - Concourse CI/CD and Pipelines
Deep dive  - Concourse CI/CD and PipelinesDeep dive  - Concourse CI/CD and Pipelines
Deep dive - Concourse CI/CD and Pipelines
 
OS Lab Manual.pdf
OS Lab Manual.pdfOS Lab Manual.pdf
OS Lab Manual.pdf
 
Docker 101
Docker 101Docker 101
Docker 101
 
C-PROGRAMMING-LANGUAGE.pptx
C-PROGRAMMING-LANGUAGE.pptxC-PROGRAMMING-LANGUAGE.pptx
C-PROGRAMMING-LANGUAGE.pptx
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Installing Software, Part 3: Command Line
Installing Software, Part 3: Command LineInstalling Software, Part 3: Command Line
Installing Software, Part 3: Command Line
 

Recently uploaded

Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 

Recently uploaded (20)

Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 

Linux shell ggsipu-lug

  • 2. WHAT’S THE SHELL? ● The shell (‘command line’) is a program that takes commands from you and gives them to the OS to perform. ● Before GUIs came around, the shell was the only way to interact with the OS. ● Even though GUIs are common today, it’s important to know how to use the shell if you want to use the full power of Linux ● Many different shell programs exist, but the most common one is called bash - short for Bourne Again SHell (since it was written by Steve Bourne).
  • 3. WHY USE A SHELL? ● GUIs are good at a lot of things, but they’re not good at everything. ● Using the shell can simplify your work and help you automate your tasks. Moreover, there are some things you just can’t do with a GUI. ● Here’s a little shell command that outputs the top ten largest files on your hard drive to a file called ‘diskuse.txt’ du -h | sort -h | tail > diskuse.txt ● Doing that on the GUI requires a specialized program written in a hundred or so lines of code.
  • 4. SHELL BASICS ● You can access a shell on pretty much any Linux system by hitting Ctrl + Alt + F1 - F6. ● Each of these key combinations produces a ‘new’ terminal - a bit like having six different screens, of which you can see one at a time. ● Once on a shell, you may get a prompt for a login and a password. Enter that, and you’ll get something like this ● Let’s take a closer look here.
  • 5. SHELL BASICS The text before the blinking cursor here is what we call a ‘prompt’, and it provides information about the computer you’re working on. The prompt here is puranjay@Slack:~$ There are four parts to this: puranjay is my username on the computer @Slack is the hostname (the ‘name’) of the computer ~ (the part after the :) means that I’m currently in my home directory $ means that I’m a normal user (not root)
  • 6. THREE VITAL COMMANDS which shows you which directory you are currently working in ● pwd , ● ls, which shows you the contents of the current directory ● cd, which allows you to change your directory
  • 7. COMPILING C/C++ PROGRAMS ● Linux comes with a great C language compiler called gcc. Generally, it’s pre-installed, but on some Ubuntu boxes, it’s not. If you’re using one of those boxes, you can install it from the internet by typing this in the shell: sudo aptitude install build-essential ● Once you have gcc up and running, you can use it to compile C programs. I’ve written a very basic program here (in notepad) as an example, and saved it as helloworld.c
  • 8. OUR EXAMPLE C PROGRAM /* Small C Program to demonstrate the use of gcc */ #include <stdio.h> int main() { printf (“Hello, world.n”); return 0; } /* End program*/ I’ve gone ahead and saved this program as helloworld.c in the /home/puranjay/Demo folder.
  • 9. OUR EXAMPLE C PROGRAM Before we can compile our program, we have to find the folder it’s in. First step : Find out where we are. A pwd command results in ‘/home/puranjay’. Now, I stored our program in the folder /home/puranjay/Demo’, so let’s try to get there. I’ve done cd Demo to change my directory to ‘Demo’, and then did a pwd, which confirms that I’m now in the right directory /home/puranjay/Demo
  • 10. OUR EXAMPLE C PROGRAM Just for fun, let’s check out the contents of our current directory, by doing an ls command. The ls command shows that there are four objects here. The first three, with a / in front of their name are directories (folders), and our shell has highlighted them in blue. Next to the directories, sure enough, is our C file, helloworld.c Now that we’re in the right folder, it’s time to start compiling.
  • 11. USING GCC ● gcc, like all compilers, is a complex piece of software in itself, consisting of over 7 million lines of code. It has numerous options for code optimization, error reporting, permissiveness and so forth. ● Since our program is a simple one, we needn’t be concerned with all the options. All we need is a simple command. ● Our command is gcc helloworld.c -o output The part right after gcc is our filename, helloworld.c .After providing the filename, we’ve added -o ouput which tells the compiler to make an executable output file called output
  • 12. USING GCC Another ls command reveals that the file output has now been created. It is marked with a * by our shell, to show that it is an executable file - it can be run. To run it, we’re just going to type its name in the shell. And there you go! Our program runs just as expected, displaying ‘Hello, world.’ on the screen.