Difference between revisions of "User:Mukund-pondkule-6a11@uni-paderborn.de"
Line 323: | Line 323: | ||
To bring a process to foreground: | To bring a process to foreground: | ||
Type fg (bring it to foreground). | Type fg (bring it to foreground). | ||
+ | |} | ||
+ | |||
+ | |||
+ | === The vim text editor === <!--T:8--> | ||
+ | |||
+ | |||
+ | Video: Slide 91 - 99 (9 pages), 5 min 0 sec (Text + Demo) + 15 sec (Quiz) | ||
+ | |||
+ | Text and slides path | ||
+ | |||
+ | Quiz: | ||
+ | 1. How to enter the insert mode of vim ? | ||
+ | A: press <code>enter [references][operator][modes]</code> key | ||
+ | B: press <code>i [references][operator][modes]</code> key | ||
+ | C: press <code>Esc [references][operator][modes]</code> key | ||
+ | {| role="presentation" class="wikitable mw-collapsible mw-collapsed" | ||
+ | | <strong>Answer:</strong> | ||
+ | |- | ||
+ | | B | ||
+ | | Explanation: If you are not in the insert mode, the <code>i[references][operator][modes]</code> key means insert and by pressing it you can enter the insert mode. On the other hand, the <code>Esc[references][operator][modes]</code> key brings you out of the insert mode. The behavior of the <code>enter[references][operator][modes]</code> key depends on in which mode of vim you are. If you are in the normal mode, you navigate to the next line. If you are in the insert mode already, you start a new line. | ||
|} | |} |
Revision as of 11:39, 8 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
Answer: | |
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)
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
Answer: | |
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. |
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
Answer: |
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.
Answer: |
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.
Answer: |
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.
Explanation: |
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.
Explanation: |
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:\
Answer: | |
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.
Answer: | |
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: | 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.
Answer: |
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.
Answer: |
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 cp <old_dir> <new_dir> ? A: Yes B: No, -r option is needed for copying directory
Answer: | |
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: | 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.
Answer: |
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.
Answer: |
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
Answer: | |
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
Answer: |
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
Answer: |
$ 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
Answer: | |
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.
Answer: |
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)
Answer: |
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.
Hint: |
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). |
The vim text editor
Video: Slide 91 - 99 (9 pages), 5 min 0 sec (Text + Demo) + 15 sec (Quiz)
Text and slides path
Quiz:
1. How to enter the insert mode of vim ? A: pressenter [references][operator][modes]
key B: pressi [references][operator][modes]
key C: pressEsc [references][operator][modes]
key
Answer: | |
B | Explanation: If you are not in the insert mode, the i[references][operator][modes] key means insert and by pressing it you can enter the insert mode. On the other hand, the Esc[references][operator][modes] key brings you out of the insert mode. The behavior of the enter[references][operator][modes] key depends on in which mode of vim you are. If you are in the normal mode, you navigate to the next line. If you are in the insert mode already, you start a new line.
|