Difference between revisions of "User:Mukund-pondkule-6a11@uni-paderborn.de"

From HPC Wiki
Jump to navigation Jump to search
(Blanked the page)
Tag: Blanking
Line 1: Line 1:
 +
An Introduction to the Linux Operating System and Command Line. The course provides students with a hands-on approach for learning Linux through assignments and projects. 
  
 +
__TOC__
 +
 +
== Historical Background ==
 +
Video: Slide 17 - 23 (7 pages), 5 min 45 sec (Text) + 15 sec (Quiz)
 +
 +
Text and slides path
 +
 +
Quiz:
 +
1. Are all Top 500 supercomputers using Linux in HPC?
 +
  A: Yes
 +
  B: No
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    | A
 +
    | Explanation: see https://top500.org/statistics/list (access on 27.08.2020) List in June 2020 shows all Top 500 supercomputers are using Linux.
 +
    |}
 +
           
 +
2. What does GNU stands for?
 +
  A. GNU's Not Unix
 +
  B. Geek Needed Unix
 +
  C. General Unix
 +
  D. General Unix
 +
  E. None of the Above
 +
  Answer: a)
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    | A
 +
    |}
 +
Exercises in Terminal: no exercises in this section
 +
 +
== The Command Line ==
 +
Video: Slide 17 - 23 (7 pages), 5 min 45 sec (Text) + 15 sec (Quiz)
 +
 +
Text and slides path
 +
 +
 +
 +
Quiz:
 +
1. Which keys can be used for command history?
 +
  A: up- and down-arrow keys
 +
  B: Page-up and Page-down keys
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    | A
 +
    | Explanation: up- and down-arrow keys (↑ and ↓) can be used for command history. The behavior of Page-up and Page-down keys depends on the setting of a terminal. But normally the command history is not available by using the Page-up and Page-down keys.
 +
    |}
 +
{{Warning|mode=info|text=Working directory in console reminds user, where they are. (page 3)}}
 +
{{Warning|mode=warn|
 +
  text=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
 +
  {| 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.
 +
    |}
 +
 +
== Directory structure ==         
 +
Video: Slide 33 - 48 (16 pages), 5 min 45 sec (Text + Demo + Quiz) + 15 sec (Tips and Warning)
 +
 +
Text and slides path
 +
 +
 +
 +
Quiz:
 +
1. Which one is the top directory in Linux?
 +
  A: /
 +
  B: /home
 +
  C: C:\
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |    A
 +
    | Explanation: The tree structure for directory is used in Linux system. Therefore the top directory in Linux is /. The /home directory may be an upper level directory for all non-root users. The last option C:\ represents the C drive on Windows.
 +
    |}
 +
 +
2. The command 'cd ' without arguments : if you start in var/log/ and run cd with no arguments, what do you expect will happen?
 +
  A: Nothing it stays in /var/log/.
 +
  B: It goes to your home directory.
 +
  C: It goes to the filesystem root
 +
  D: The shell prompt turns into a shark and eats you.
 +
  E: It’s an error.
 +
  F: The shell stops having a working directory.
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |    B
 +
    | It goes to your home directory. cd without arguments is a shortcut to take you home. As long as your home directory exists, you can always go home.
 +
    |}
 +
{{Warning|mode=warn|text=no undo and make sure what you want to do (page 16)}}
 +
 +
Exercises in Terminal (slide 49):
 +
1. Go to a specific subfolder of a folder (example: cd Documents/courses/ ) and get back to the home directory using cd command. List 3 different ways to do it using one command. check after every action your path with pwd command.
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |
 +
        cd
 +
        cd ~
 +
        cd $HOME
 +
        the last option $HOME is an enviornment variable. You will learn about enviornment variables later.
 +
    |}
 +
     
 +
2. Go to the directory /tmp and jump between /tmp and your home directory back and forth. check after every action your path with pwd command.
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |
 +
        cd /tmp
 +
        cd -
 +
        cd - with cd - you change back to the previous working directory, pass the dash (-) character as an argument to the cd command.
 +
    |}
 +
 +
== Files ==
 +
Video: Slide 51 - 56 (6 pages), 5 min 30 sec (Text + Demo + Quiz) + 15 sec (Tips and Warning)
 +
 +
Text and slides path
 +
 +
 +
Quiz:
 +
1. Can you copy directory with </code>cp <old_dir> <new_dir></code> ?
 +
  A: Yes
 +
  B: No, -r option is needed for copying directory
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    | B
 +
    | Explanation: Without any option the cp command can only be used to copy files (text files as well as binary files). To copy a directory, the -r option must be used and it means to copy a given directory in a recursive manner e.g. one file after another in a directory.
 +
    |}
 +
{{Warning|mode=warn|text= rm -f: no confirmation! Use with care (page 3).
 +
    Wildcards expand before given to program (page 6).}}
 +
 +
Exercises in Terminal:
 +
1. Use the find command to search for files, whose name ends with dat, in your home directory.
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |
 +
      The complete command is find $HOME -type f -name "*dat"
 +
          find can be used to search files and directories.
 +
          $HOME is your home directory.
 +
          -type f means only file (not directory) will be shown.
 +
          -name "*dat" specifies the required filename and "*dat" restricts the filename ends with dat, while it can begin with any characters (the * wild cards).
 +
    |}
 +
2. Use the find command to search for directories, whose name begins with test and ends with _dir, in your home directory.
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |
 +
      The complete command is find $HOME -type d -name "test*_dir"
 +
          find can be used to search files and directories.
 +
          $HOME is your home directory.
 +
          -type d means only directory (not file) will be shown.
 +
          -name "test*_dir" specifies the required directory name, which begins with test and ends with _dir. The wild card * matches any characters in between.
 +
    |}
 +
 +
== Text display, search ==
 +
Video: Slide 58 - 64 (7 pages), 5 min 40 sec (Text + Demo) + 15 sec (Quiz)
 +
 +
Text and slides path
 +
 +
Quiz:
 +
1. Which command can be used to append text to filename?
 +
  A: command > filename
 +
  B: command >> filename
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    | B
 +
    | Explanation: The > operator redirects the output of command into filename. If filename exists already, its contents will be overwritten. The >> operator can redirect the output of command into filename as well, except that if filename exists, the new data are appended instead of overwritten.
 +
    |}
 +
 +
2. How do I find all files containing specific text on Linux?
 +
    HINT: use grep command
 +
    {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |
 +
      grep -rnw '/path/to/somewhere/' -e 'pattern'
 +
            -r or -R is recursive.
 +
            -n is line number.
 +
            -w stands for match the whole word.
 +
            -l (lower-case L) can be added to just give the file name of matching files.
 +
    |}
 +
 
 +
Exercises in Terminal (slide 65):
 +
1. Create a file using cat (some filename) and write some text in it as below. than use grep to find and display the line number and the line with the word Alan in the file.
 +
        the best way to predict
 +
        the future is to invent it
 +
        –  Alan Kay
 +
    {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |
 +
      $ cat > quote.txt <<"EOF" \ > the best way to predict \ > the future is to invent it
 +
      >  - Alan Kay
 +
      > EOF
 +
      EOF mean end of file. Press enter to get a new line while writing text. With cat > filename you write the file content in the file quote.txt.
 +
 +
      Further use grep as below
 +
      $ grep -in alan quote.txt
 +
      3: - Alan Kay
 +
      grep command option -
 +
            - i to ignore case distinctions, so that characters that differ only in case match each other.
 +
            - n for line number   
 +
    |}
 +
 +
== Processes and permissions ==
 +
Video: Slide 67 - 88 (22 pages), 7 min 40 sec (Text + Demo)
 +
 +
Text and slides path 
 +
 +
Quiz:
 +
1. Which command can prevent other users not in your group from writing to input.dat?
 +
  A: chmod u-w input.dat
 +
  B: chmod o-w input.dat
 +
  C: chmod g-w input.dat
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    | B
 +
    | Explanation: The chmod command changes file permission.
 +
            u represents the user who owns the file.
 +
            g means other users in your group.
 +
            o stands for other users not in your group.
 +
            -w means to remove the write permission.
 +
      Therefore B is the correct answer.
 +
    |}
 +
 +
Exercises in Terminal (slide 89):
 +
1. Create an empty file, make it read-only, make it executable.
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |
 +
      Create an empty file: touch file.txt.
 +
      make it read-only: chmod a-w file.txt; chmod a-x file.txt; chmod a+r file.txt.
 +
      make it executable: chmod a+x file.txt.
 +
 +
      Explanation: The touch command can be used to create an empty file. In this example it is file.txt.
 +
          chmod a-w file.txt; chmod a-x file.txt; chmod a+r file.txt means to execute the three commands subsequently.
 +
          chmod a-w file.txt removes the write permission for all users.
 +
          chmod a-x file.txt removes the executable permission for all users.
 +
          chmod a+r file.txt adds the read permission for all users.
 +
          chmod a+x file.txt makes file.txt executable for all users.
 +
    |}
 +
 +
2. Start a process (e.g. sleep 10m)
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Answer:</strong>
 +
    |-
 +
    |
 +
      Use a second console to look at it in top.
 +
      Kill it.
 +
      Hint:
 +
        To kill the started process (e.g. sleep 10m):
 +
        1. Go to the terminal that started the process.
 +
        2. Press Ctrl-C to kill it.
 +
    |}
 +
 +
3. Start a process, bring it into background/foreground.
 +
  {| role="presentation" class="wikitable mw-collapsible mw-collapsed"
 +
    | <strong>Hint:</strong>
 +
    |-
 +
    |
 +
      To bring a process to background:
 +
        Press Ctrl-Z (pause the process).
 +
        Type bg (bring it to background).
 +
      To bring a process to foreground:
 +
        Type fg (bring it to foreground).
 +
    |}

Revision as of 11:44, 7 September 2020

An Introduction to the Linux Operating System and Command Line. The course provides students with a hands-on approach for learning Linux through assignments and projects.

Historical Background

Video: Slide 17 - 23 (7 pages), 5 min 45 sec (Text) + 15 sec (Quiz)

Text and slides path

Quiz:

1. Are all Top 500 supercomputers using Linux in HPC?
  A: Yes
  B: No
2. What does GNU stands for?
  A. GNU's Not Unix
  B. Geek Needed Unix
  C. General Unix
  D. General Unix
  E. None of the Above
  Answer: a)

Exercises in Terminal: no exercises in this section

The Command Line

Video: Slide 17 - 23 (7 pages), 5 min 45 sec (Text) + 15 sec (Quiz)

Text and slides path


Quiz:

1. 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.

Directory structure

Video: Slide 33 - 48 (16 pages), 5 min 45 sec (Text + Demo + Quiz) + 15 sec (Tips and Warning)

Text and slides path


Quiz:

1. Which one is the top directory in Linux?
  A: /
  B: /home
  C: C:\
2. The command 'cd ' without arguments : if you start in var/log/ and run cd with no arguments, what do you expect will happen?
  A: Nothing it stays in /var/log/.
  B: It goes to your home directory.
  C: It goes to the filesystem root
  D: The shell prompt turns into a shark and eats you.
  E: It’s an error.
  F: The shell stops having a working directory.
Warning:  no undo and make sure what you want to do (page 16)

Exercises in Terminal (slide 49):

1. Go to a specific subfolder of a folder (example: cd Documents/courses/ ) and get back to the home directory using cd command. List 3 different ways to do it using one command. check after every action your path with pwd command.
2. Go to the directory /tmp and jump between /tmp and your home directory back and forth. check after every action your path with pwd command.

Files

Video: Slide 51 - 56 (6 pages), 5 min 30 sec (Text + Demo + Quiz) + 15 sec (Tips and Warning)

Text and slides path


Quiz:

1. Can you copy directory with cp <old_dir> <new_dir> ? 
  A: Yes
  B: No, -r option is needed for copying directory
Warning:  rm -f: no confirmation! Use with care (page 3). Wildcards expand before given to program (page 6).

Exercises in Terminal:

1. Use the find command to search for files, whose name ends with dat, in your home directory.
2. Use the find command to search for directories, whose name begins with test and ends with _dir, in your home directory.

Text display, search

Video: Slide 58 - 64 (7 pages), 5 min 40 sec (Text + Demo) + 15 sec (Quiz)

Text and slides path

Quiz:

1. Which command can be used to append text to filename?
  A: command > filename
  B: command >> filename
2. How do I find all files containing specific text on Linux?
   HINT: use grep command

Exercises in Terminal (slide 65):

1. Create a file using cat (some filename) and write some text in it as below. than use grep to find and display the line number and the line with the word Alan in the file.
        the best way to predict
        the future is to invent it
        –  Alan Kay

Processes and permissions

Video: Slide 67 - 88 (22 pages), 7 min 40 sec (Text + Demo)

Text and slides path

Quiz:

1. Which command can prevent other users not in your group from writing to input.dat? 
  A: chmod u-w input.dat
  B: chmod o-w input.dat
  C: chmod g-w input.dat

Exercises in Terminal (slide 89):

1. Create an empty file, make it read-only, make it executable.
2. Start a process (e.g. sleep 10m)
3. Start a process, bring it into background/foreground.