Difference between revisions of "Introduction to Linux in HPC/The Command Line"

From HPC Wiki
Introduction to Linux in HPC/The Command Line
Jump to navigation Jump to search
(Created page with "__TOC__ === Video === <!--T:5--> <youtube width="600" height="400" right>IfD9IPixgpo</youtube> [https://git-ce.rwth-aachen.de/hpc.nrw/ap2/tutorials/linux/-/blob/master/Slid...")
 
Line 60: Line 60:
 
{{hidden end}}
 
{{hidden end}}
  
{{Warning|mode=info|text= '''no tips in this section'''}}
+
{{Warning|mode=info|text= '''Working directory in console reminds user, where they are. (page 3)'''}}
  
{{Warning|mode=warn|text= '''no warning in this section'''}}
+
{{Warning|mode=warn|text= '''
 +
    In command line user may forget where they are. (page 2)</br>
 +
    Child processes may stop, if parent shell exits. (page 2)
 +
'''}}
 +
 
 +
 
 +
=== Exercises in Terminal === <!--T:5-->
 +
 
 +
1. What's your username on a Linux computer?
 +
  There are two ways to find your username on a Linux computer
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |
 +
      1. In the command line prompt, e.g. [username@hostname ~]$ , you can find your username as username directly.
 +
      2. The Linux command whoami can also show your username.
 +
    |}
 +
2. What's the hostname of a Linux computer?
 +
  There are two ways to find the hostname on a Linux computer.
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |
 +
      1. In the command line prompt, e.g. [username@hostname ~]$ , you can find the hostname as hostname directly.
 +
      2. The Linux command hostname can also give you the hostname.
 +
    |}
 +
           
 +
3. What's your current working directory on a Linux computer?
 +
    There are two ways to find your current working directory on a Linux computer.
 +
    {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |
 +
      1. In the command line prompt, e.g. [username@hostname ~]$ , you can find your current working directory is ~, which means your $HOME directory.
 +
      2. The Linux command pwd can also show your current working directory.
 +
    |}
 +
           
 +
4.  Use up- and down-arrow keys to see the command history.
 +
    {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Explanation:</strong>
 +
    |-
 +
    |
 +
      The up- and down- arrow keys can be used to navigate command history.
 +
    |}
 +
       
 +
5.  Run sleep 1h command and wait, then use Ctrl-C to kill it.
 +
    {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Explanation:</strong>
 +
    |-
 +
    |
 +
      sleep 1h puts the terminal into idle, e.g. terminal is doing nothing, for 1 hour.
 +
      Ctrl-C kills the current command. In this exercise it's sleep 1h.
 +
    |}

Revision as of 17:01, 1 October 2020

Video

Linux Introduction Slides 25 - 31 (7 pages)

Slide Layout

   page 1: 
       You type commands in command line to use Linux
       Similar things: console, terminal, CLI and shell (interchangeable in this course)
       command line: advantages (fast) vs. disadvantages (hard to master)
   page 2: 
       Shell in Linux is widely used.
       Warnings:
           User may forget where they are.
           Child processes may stop, if parent shell exits.
   page 3: 
       Elements in console:
           User name
           Host name
           Working directory: reminder for user (where they are)
           Command prompt
   page 4: 
       Elements in console (cont.):
           Command and its options
           Output
           Current command running or new command prompt
   page 5: 
       Demo 1: (slide 15 sec + terminal 45 sec)
           run command
           arrow keys for history
           tab key for auto-completion
           Ctrl-C to abort
   page 6: 
       Warning: command is always case-sensitive
       command line options: minus sign: double minus vs. single minus
   page 7: 
       Demo 2: (slide 15 sec + terminal 30 sec)
       use internet for help
       man page
       built-in help


Quiz

Which keys can be used for command history?

A. up- and down-arrow keys
B. Page-up and Page-down keys


Info:  Working directory in console reminds user, where they are. (page 3)


Warning: 
   In command line user may forget where they are. (page 2)
Child processes may stop, if parent shell exits. (page 2)


Exercises in Terminal

1. What's your username on a Linux computer?
  There are two ways to find your username on a Linux computer 
2. What's the hostname of a Linux computer?
  There are two ways to find the hostname on a Linux computer.
3. What's your current working directory on a Linux computer?
   There are two ways to find your current working directory on a Linux computer.
4.  Use up- and down-arrow keys to see the command history.
5.  Run sleep 1h command and wait, then use Ctrl-C to kill it.