SlideShare a Scribd company logo
Introduction
    Working on the command line
                         Manuals
     Essential command line tools




                                    Command line essentials

                                          Bart Van Loon


                                        1st February 2012




1 / 30                                               Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools




         1 Introduction


         2 Working on the command line
               bash
               bash prompt
               some bash features

         3 Manuals


         4 Essential command line tools




2 / 30                                    Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 Some ancient history
         When computers were big, incomprehensible beasts, like




         you could “talk” to it using punched cards, paper tape or a
         terminal.
3 / 30                                         Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 Some ancient history
         This is such a computer terminal:




         The famous DEC VT100 (1978).
4 / 30                                       Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 Some ancient history
         These terminals gave you an interface for text entry and display
         through various standard “streams”.




5 / 30                                          Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 A little less ancient now
         Today, most UNIX-like operating systems such as Linux and
         FreeBSD have virtual terminals to provide several text terminals on
         a single computer to let you interface with the computer itself.




         If you’re in X now, try to press ctrl-alt-F1, ctrl-alt-F2, . . .
6 / 30                                         Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 Modern times

         In today’s graphical world, we have terminal emulators, like

           xterm
           gnome-terminal
           rxvt
           ...




7 / 30                                          Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 Modern times
         These terminal emulators run text-based applications. The most
         fundamental types of such applications are shells, like

           bash
           tcsh
           zsh
           ...




         A shell gives you a command line interface (CLI).
8 / 30                                         Bart Van Loon   Command line essentials
Introduction
                                    bash
    Working on the command line
                                    bash prompt
                         Manuals
                                    some bash features
     Essential command line tools

 Working on the command line




         Let’s assume you are running bash.
              bash is program, namely a shell meant for interactive use
              bash is also a powerful scripting language




9 / 30                                                   Bart Van Loon   Command line essentials
Introduction
                                    bash
    Working on the command line
                                    bash prompt
                         Manuals
                                    some bash features
     Essential command line tools

 bash in interactive mode



          When it starts, it runs one or more scripts:
             When started as an interactive login shell:
                      /etc/profile
                      ~/.bash profile, ~/.bash login, or ~/.profile
              When exited as a login shell:
                      ~/.bash logout
              When started as an interactive shell (but not a login shell):
                      ~/.bashrc




10 / 30                                                  Bart Van Loon   Command line essentials
Introduction
                                    bash
    Working on the command line
                                    bash prompt
                         Manuals
                                    some bash features
     Essential command line tools

 Your bash prompt



          Let’s start with what you see:

                                        bbbart@tuxitree:~$

                bbbart : my username
              tuxitree : computer’s hostname
                         ˜ : present working directory (˜ is the home directory)
                         $ : this means I am not root




11 / 30                                                  Bart Van Loon   Command line essentials
Introduction
                                    bash
    Working on the command line
                                    bash prompt
                         Manuals
                                    some bash features
     Essential command line tools

 Your bash prompt



          You can change the look of this prompt! Why would you do so?
              it looks cool;
              it’s useful to keep track of system information;
              different machines/users can get different colours;
              have information about work environment available at all time;
              to quickly spot the prompt when you use scrollback;
              ...




12 / 30                                                  Bart Van Loon   Command line essentials
Introduction
                                    bash
    Working on the command line
                                    bash prompt
                         Manuals
                                    some bash features
     Essential command line tools

 Your bash prompt


          Your prompt configuration is stored in the variable PS1.
                                    $ echo $PS1
                                    u@h:w$



                       u : user’s username
                       h : computer’s hostname
                      w : present working directory
                       $ : $ when user is not root, # when user is root



13 / 30                                                  Bart Van Loon   Command line essentials
Introduction
                                    bash
    Working on the command line
                                    bash prompt
                         Manuals
                                    some bash features
     Essential command line tools

 Your bash prompt


          Try the following command (put it on one line with spaces in
          between):


          PS1=’[e[1;32m]u@H:[e[m]
          [e[1;37m]w[e[m]n[e[1;33m]hist:!
          [e[0;33m] [e[1;31m]jobs:j $[e[m] ’


          Now go an find the prompt that suits you best!



14 / 30                                                  Bart Van Loon   Command line essentials
Introduction
                                    bash
    Working on the command line
                                    bash prompt
                         Manuals
                                    some bash features
     Essential command line tools

 Keyboard shortcuts

          Some useful keyboard shortcuts:
                     tab : autocomplete from the cursor position
               ctrl-a : move cursor to the line start
               ctrl-c : send the SIGINT signal to the current task
               ctrl-d : send an EOF marker (if the line is empty)
               ctrl-e : move cursor to the line end
               ctrl-k : clear the line after the cursor
               ctrl-l : clear the screen content
               ctrl-u : clear the line before the cursor
               ctrl-z : send the SIGTSTP signal to the current task


15 / 30                                                  Bart Van Loon   Command line essentials
Introduction
                                    bash
    Working on the command line
                                    bash prompt
                         Manuals
                                    some bash features
     Essential command line tools

 Stream redirecting

          Remember the streams to interact with a terminal (stdin,
          stdout, stderr). You can redirect them!


                        > : redirect stdout
                      2> : redirect stderr
                        < : redirect stdin


          Special one:
                     >> : redirect stdout, but append to the output



16 / 30                                                  Bart Van Loon   Command line essentials
Introduction
                                      bash
    Working on the command line
                                      bash prompt
                         Manuals
                                      some bash features
     Essential command line tools

 Piping



          You can also “pipe” streams to link commands:

                                       $ program1 | program2

          is the same as
                                    $ program1 > tempfile
                                    $ program2 < tempfile
                                    $ rm tempfile




17 / 30                                                    Bart Van Loon   Command line essentials
Introduction
                                    bash
    Working on the command line
                                    bash prompt
                         Manuals
                                    some bash features
     Essential command line tools

 Piping




18 / 30                                                  Bart Van Loon   Command line essentials
Introduction
                                    bash
    Working on the command line
                                    bash prompt
                         Manuals
                                    some bash features
     Essential command line tools

 Learn from history


          DRY is also a principle on the shell:
              ↑ and ↓ : navigate through your history
               ctrl-r : search the command history
             history : print your recent history
                 !<n> : repeat command number <n>
                       !! : repeat the last command
                       !$ : special variable that contains the last word of the
                          previous command




19 / 30                                                  Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 Before we begin. . .

          The most important command you’ll ever learn, is man:
                     man : format and display the manual pages

          Most manual pages contain a synopsis of the command in
          question:
              mysql [options] db name
              mysql can take some options but has to have a name of a
              database as argument
              xpdf [options] [PDF-file [page | +dest]]
              xpdf can take some options and a PDF-file as arguments. If
              you pass a PDF-file as argument you can also give it a page or
              a destination, preceded by a +-symbol.

          Now check the synopsis of the ssh command.
20 / 30                                          Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 Essential command line tools


          “The right tool for the right job”
                     cut : remove sections from each line of files
                       du : estimate file space usage
                   grep : print lines matching a pattern
                   head : output the first part of files
                   nice : run a program with modified scheduling priority
                   sort : sort lines of text files
                   tail : output the last part of files
                       wc : print newline, word, and byte counts



21 / 30                                             Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 cut


                 Name : cut
           Description : remove sections from each line of files
             Synopsis : cut OPTION...      [FILE]...


          Useful options:
            -d DELIM : use DELIM instead of TAB for field delimiter
             -f LIST : select only these fields

          A LIST is made up or ranges separated by commas. A range is N,
          N-, N-M or -M.


22 / 30                                          Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 du


                 Name : du
           Description : estimate file space usage
             Synopsis : du [OPTION]...          [FILE]...


          Useful options:
                       -c : produce a grand total
                       -s : display only a total for each argument
                       -h : print sizes in human readable format



23 / 30                                             Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 grep


                 Name : grep
           Description : print lines matching a pattern
             Synopsis : grep [OPTIONS] PATTERN [FILE...]


          Useful options:
                       -i : ignore case distinctions in the PATTERN
                       -v : invert the sense of matching, to select
                          non-matching lines
                       -n : prefix each line of output with the 1-based line
                          number within its input file


24 / 30                                             Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 head



                 Name : head
           Description : output the first part of files
             Synopsis : head [OPTION]...          [FILE]...



          Useful options:
                   -n K : print the first K lines instead of the first 10




25 / 30                                            Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 nice



                 Name : nice
           Description : run a program with modified scheduling priority
             Synopsis : nice [OPTION] [COMMAND [ARG]...]



          Useful options:
                   -n N : add integer N to the niceness (default 10)




26 / 30                                           Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 sort


                 Name : sort
           Description : sort lines of text files
             Synopsis : sort [OPTION]...           [FILE]...


          Useful options:
                       -h : compare human readable numbers
                       -n : compare according to string numerical value
                       -r : reverse the result of comparisons
                       -u : output only the first of an equal run


27 / 30                                            Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 tail


                 Name : tail
           Description : output the last part of files
             Synopsis : tail [OPTION]...          [FILE]...



          Useful options:
                       -f : output appended data as the file grows
                   -n K : print the last K lines instead of the last 10




28 / 30                                            Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 wc



                 Name : wc
           Description : print newline, word, and byte counts for each file
             Synopsis : wc [OPTION]...          [FILE]...



          Useful options:
                       -l : print the newline counts




29 / 30                                            Bart Van Loon   Command line essentials
Introduction
    Working on the command line
                         Manuals
     Essential command line tools

 References




              http://en.wikipedia.org/wiki/Computer_terminal
              http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29
              http://tldp.org/HOWTO/Bash-Prompt-HOWTO
              http://en.wikipedia.org/wiki/Redirection_%28computing%29




30 / 30                                        Bart Van Loon   Command line essentials

More Related Content

Similar to Command line essentials

Bash shell programming in linux
Bash shell programming in linuxBash shell programming in linux
Bash shell programming in linuxNorberto Angulo
 
Linux Bash.pdf
Linux Bash.pdfLinux Bash.pdf
Linux Bash.pdf
VishnuGone
 
L lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdfL lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdfhellojdr
 
Linux: Beyond ls and cd
Linux: Beyond ls and cdLinux: Beyond ls and cd
Linux: Beyond ls and cdjacko91
 
Shell intro
Shell introShell intro
Shell intro
Srikanth Learner
 
Lab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptxLab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptx
NourhanTarek23
 
Unix shell story
Unix shell storyUnix shell story
Unix shell story
Quyen Le Van
 
BASIC Programming Language
BASIC Programming LanguageBASIC Programming Language
BASIC Programming Language
Jeff Valerio
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
VIKAS TIWARI
 
3.1.b how to - colors and prompts in bash
3.1.b how to - colors and prompts in bash3.1.b how to - colors and prompts in bash
3.1.b how to - colors and prompts in bash
Acácio Oliveira
 
101 3.2.1 how-to colors and prompts in bash
101 3.2.1 how-to colors and prompts in bash101 3.2.1 how-to colors and prompts in bash
101 3.2.1 how-to colors and prompts in bash
Acácio Oliveira
 

Similar to Command line essentials (14)

Bash shell programming in linux
Bash shell programming in linuxBash shell programming in linux
Bash shell programming in linux
 
Linux Bash.pdf
Linux Bash.pdfLinux Bash.pdf
Linux Bash.pdf
 
Shell intro
Shell introShell intro
Shell intro
 
L lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdfL lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdf
 
Linux: Beyond ls and cd
Linux: Beyond ls and cdLinux: Beyond ls and cd
Linux: Beyond ls and cd
 
Shell intro
Shell introShell intro
Shell intro
 
Shell intro
Shell introShell intro
Shell intro
 
Unix practical file
Unix practical fileUnix practical file
Unix practical file
 
Lab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptxLab 7 - Bash Script.pptx
Lab 7 - Bash Script.pptx
 
Unix shell story
Unix shell storyUnix shell story
Unix shell story
 
BASIC Programming Language
BASIC Programming LanguageBASIC Programming Language
BASIC Programming Language
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
3.1.b how to - colors and prompts in bash
3.1.b how to - colors and prompts in bash3.1.b how to - colors and prompts in bash
3.1.b how to - colors and prompts in bash
 
101 3.2.1 how-to colors and prompts in bash
101 3.2.1 how-to colors and prompts in bash101 3.2.1 how-to colors and prompts in bash
101 3.2.1 how-to colors and prompts in bash
 

More from Bart Van Loon

Why study Computer Science?
Why study Computer Science?Why study Computer Science?
Why study Computer Science?
Bart Van Loon
 
The Entrepreneurial Engineer
The Entrepreneurial EngineerThe Entrepreneurial Engineer
The Entrepreneurial Engineer
Bart Van Loon
 
Mission, Vision and Strategy in organisations
Mission, Vision and Strategy in organisationsMission, Vision and Strategy in organisations
Mission, Vision and Strategy in organisations
Bart Van Loon
 
Cultural Learnings of Pakistan for Make Benefit Glorious Nation of Belgium
Cultural Learnings of Pakistan for Make Benefit Glorious Nation of BelgiumCultural Learnings of Pakistan for Make Benefit Glorious Nation of Belgium
Cultural Learnings of Pakistan for Make Benefit Glorious Nation of Belgium
Bart Van Loon
 
Open Source in your company
Open Source in your companyOpen Source in your company
Open Source in your company
Bart Van Loon
 
General introduction to Open Source
General introduction to Open SourceGeneral introduction to Open Source
General introduction to Open Source
Bart Van Loon
 

More from Bart Van Loon (6)

Why study Computer Science?
Why study Computer Science?Why study Computer Science?
Why study Computer Science?
 
The Entrepreneurial Engineer
The Entrepreneurial EngineerThe Entrepreneurial Engineer
The Entrepreneurial Engineer
 
Mission, Vision and Strategy in organisations
Mission, Vision and Strategy in organisationsMission, Vision and Strategy in organisations
Mission, Vision and Strategy in organisations
 
Cultural Learnings of Pakistan for Make Benefit Glorious Nation of Belgium
Cultural Learnings of Pakistan for Make Benefit Glorious Nation of BelgiumCultural Learnings of Pakistan for Make Benefit Glorious Nation of Belgium
Cultural Learnings of Pakistan for Make Benefit Glorious Nation of Belgium
 
Open Source in your company
Open Source in your companyOpen Source in your company
Open Source in your company
 
General introduction to Open Source
General introduction to Open SourceGeneral introduction to Open Source
General introduction to Open Source
 

Recently uploaded

Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 

Recently uploaded (20)

Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 

Command line essentials

  • 1. Introduction Working on the command line Manuals Essential command line tools Command line essentials Bart Van Loon 1st February 2012 1 / 30 Bart Van Loon Command line essentials
  • 2. Introduction Working on the command line Manuals Essential command line tools 1 Introduction 2 Working on the command line bash bash prompt some bash features 3 Manuals 4 Essential command line tools 2 / 30 Bart Van Loon Command line essentials
  • 3. Introduction Working on the command line Manuals Essential command line tools Some ancient history When computers were big, incomprehensible beasts, like you could “talk” to it using punched cards, paper tape or a terminal. 3 / 30 Bart Van Loon Command line essentials
  • 4. Introduction Working on the command line Manuals Essential command line tools Some ancient history This is such a computer terminal: The famous DEC VT100 (1978). 4 / 30 Bart Van Loon Command line essentials
  • 5. Introduction Working on the command line Manuals Essential command line tools Some ancient history These terminals gave you an interface for text entry and display through various standard “streams”. 5 / 30 Bart Van Loon Command line essentials
  • 6. Introduction Working on the command line Manuals Essential command line tools A little less ancient now Today, most UNIX-like operating systems such as Linux and FreeBSD have virtual terminals to provide several text terminals on a single computer to let you interface with the computer itself. If you’re in X now, try to press ctrl-alt-F1, ctrl-alt-F2, . . . 6 / 30 Bart Van Loon Command line essentials
  • 7. Introduction Working on the command line Manuals Essential command line tools Modern times In today’s graphical world, we have terminal emulators, like xterm gnome-terminal rxvt ... 7 / 30 Bart Van Loon Command line essentials
  • 8. Introduction Working on the command line Manuals Essential command line tools Modern times These terminal emulators run text-based applications. The most fundamental types of such applications are shells, like bash tcsh zsh ... A shell gives you a command line interface (CLI). 8 / 30 Bart Van Loon Command line essentials
  • 9. Introduction bash Working on the command line bash prompt Manuals some bash features Essential command line tools Working on the command line Let’s assume you are running bash. bash is program, namely a shell meant for interactive use bash is also a powerful scripting language 9 / 30 Bart Van Loon Command line essentials
  • 10. Introduction bash Working on the command line bash prompt Manuals some bash features Essential command line tools bash in interactive mode When it starts, it runs one or more scripts: When started as an interactive login shell: /etc/profile ~/.bash profile, ~/.bash login, or ~/.profile When exited as a login shell: ~/.bash logout When started as an interactive shell (but not a login shell): ~/.bashrc 10 / 30 Bart Van Loon Command line essentials
  • 11. Introduction bash Working on the command line bash prompt Manuals some bash features Essential command line tools Your bash prompt Let’s start with what you see: bbbart@tuxitree:~$ bbbart : my username tuxitree : computer’s hostname ˜ : present working directory (˜ is the home directory) $ : this means I am not root 11 / 30 Bart Van Loon Command line essentials
  • 12. Introduction bash Working on the command line bash prompt Manuals some bash features Essential command line tools Your bash prompt You can change the look of this prompt! Why would you do so? it looks cool; it’s useful to keep track of system information; different machines/users can get different colours; have information about work environment available at all time; to quickly spot the prompt when you use scrollback; ... 12 / 30 Bart Van Loon Command line essentials
  • 13. Introduction bash Working on the command line bash prompt Manuals some bash features Essential command line tools Your bash prompt Your prompt configuration is stored in the variable PS1. $ echo $PS1 u@h:w$ u : user’s username h : computer’s hostname w : present working directory $ : $ when user is not root, # when user is root 13 / 30 Bart Van Loon Command line essentials
  • 14. Introduction bash Working on the command line bash prompt Manuals some bash features Essential command line tools Your bash prompt Try the following command (put it on one line with spaces in between): PS1=’[e[1;32m]u@H:[e[m] [e[1;37m]w[e[m]n[e[1;33m]hist:! [e[0;33m] [e[1;31m]jobs:j $[e[m] ’ Now go an find the prompt that suits you best! 14 / 30 Bart Van Loon Command line essentials
  • 15. Introduction bash Working on the command line bash prompt Manuals some bash features Essential command line tools Keyboard shortcuts Some useful keyboard shortcuts: tab : autocomplete from the cursor position ctrl-a : move cursor to the line start ctrl-c : send the SIGINT signal to the current task ctrl-d : send an EOF marker (if the line is empty) ctrl-e : move cursor to the line end ctrl-k : clear the line after the cursor ctrl-l : clear the screen content ctrl-u : clear the line before the cursor ctrl-z : send the SIGTSTP signal to the current task 15 / 30 Bart Van Loon Command line essentials
  • 16. Introduction bash Working on the command line bash prompt Manuals some bash features Essential command line tools Stream redirecting Remember the streams to interact with a terminal (stdin, stdout, stderr). You can redirect them! > : redirect stdout 2> : redirect stderr < : redirect stdin Special one: >> : redirect stdout, but append to the output 16 / 30 Bart Van Loon Command line essentials
  • 17. Introduction bash Working on the command line bash prompt Manuals some bash features Essential command line tools Piping You can also “pipe” streams to link commands: $ program1 | program2 is the same as $ program1 > tempfile $ program2 < tempfile $ rm tempfile 17 / 30 Bart Van Loon Command line essentials
  • 18. Introduction bash Working on the command line bash prompt Manuals some bash features Essential command line tools Piping 18 / 30 Bart Van Loon Command line essentials
  • 19. Introduction bash Working on the command line bash prompt Manuals some bash features Essential command line tools Learn from history DRY is also a principle on the shell: ↑ and ↓ : navigate through your history ctrl-r : search the command history history : print your recent history !<n> : repeat command number <n> !! : repeat the last command !$ : special variable that contains the last word of the previous command 19 / 30 Bart Van Loon Command line essentials
  • 20. Introduction Working on the command line Manuals Essential command line tools Before we begin. . . The most important command you’ll ever learn, is man: man : format and display the manual pages Most manual pages contain a synopsis of the command in question: mysql [options] db name mysql can take some options but has to have a name of a database as argument xpdf [options] [PDF-file [page | +dest]] xpdf can take some options and a PDF-file as arguments. If you pass a PDF-file as argument you can also give it a page or a destination, preceded by a +-symbol. Now check the synopsis of the ssh command. 20 / 30 Bart Van Loon Command line essentials
  • 21. Introduction Working on the command line Manuals Essential command line tools Essential command line tools “The right tool for the right job” cut : remove sections from each line of files du : estimate file space usage grep : print lines matching a pattern head : output the first part of files nice : run a program with modified scheduling priority sort : sort lines of text files tail : output the last part of files wc : print newline, word, and byte counts 21 / 30 Bart Van Loon Command line essentials
  • 22. Introduction Working on the command line Manuals Essential command line tools cut Name : cut Description : remove sections from each line of files Synopsis : cut OPTION... [FILE]... Useful options: -d DELIM : use DELIM instead of TAB for field delimiter -f LIST : select only these fields A LIST is made up or ranges separated by commas. A range is N, N-, N-M or -M. 22 / 30 Bart Van Loon Command line essentials
  • 23. Introduction Working on the command line Manuals Essential command line tools du Name : du Description : estimate file space usage Synopsis : du [OPTION]... [FILE]... Useful options: -c : produce a grand total -s : display only a total for each argument -h : print sizes in human readable format 23 / 30 Bart Van Loon Command line essentials
  • 24. Introduction Working on the command line Manuals Essential command line tools grep Name : grep Description : print lines matching a pattern Synopsis : grep [OPTIONS] PATTERN [FILE...] Useful options: -i : ignore case distinctions in the PATTERN -v : invert the sense of matching, to select non-matching lines -n : prefix each line of output with the 1-based line number within its input file 24 / 30 Bart Van Loon Command line essentials
  • 25. Introduction Working on the command line Manuals Essential command line tools head Name : head Description : output the first part of files Synopsis : head [OPTION]... [FILE]... Useful options: -n K : print the first K lines instead of the first 10 25 / 30 Bart Van Loon Command line essentials
  • 26. Introduction Working on the command line Manuals Essential command line tools nice Name : nice Description : run a program with modified scheduling priority Synopsis : nice [OPTION] [COMMAND [ARG]...] Useful options: -n N : add integer N to the niceness (default 10) 26 / 30 Bart Van Loon Command line essentials
  • 27. Introduction Working on the command line Manuals Essential command line tools sort Name : sort Description : sort lines of text files Synopsis : sort [OPTION]... [FILE]... Useful options: -h : compare human readable numbers -n : compare according to string numerical value -r : reverse the result of comparisons -u : output only the first of an equal run 27 / 30 Bart Van Loon Command line essentials
  • 28. Introduction Working on the command line Manuals Essential command line tools tail Name : tail Description : output the last part of files Synopsis : tail [OPTION]... [FILE]... Useful options: -f : output appended data as the file grows -n K : print the last K lines instead of the last 10 28 / 30 Bart Van Loon Command line essentials
  • 29. Introduction Working on the command line Manuals Essential command line tools wc Name : wc Description : print newline, word, and byte counts for each file Synopsis : wc [OPTION]... [FILE]... Useful options: -l : print the newline counts 29 / 30 Bart Van Loon Command line essentials
  • 30. Introduction Working on the command line Manuals Essential command line tools References http://en.wikipedia.org/wiki/Computer_terminal http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29 http://tldp.org/HOWTO/Bash-Prompt-HOWTO http://en.wikipedia.org/wiki/Redirection_%28computing%29 30 / 30 Bart Van Loon Command line essentials