Sem I (Prak Grund Infor) - N5 Flashcards

1
Q

Deletes the second line of the file with sed using Bash Linux.

A
sed '2d' file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Prints only the second line of the file with sed using Bash Linux.

A
sed -n '2p' file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Inserts “new line” before the second line of the file with sed using Bash Linux.

A
sed '2i\new line' file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Appends “new line” after the second line of the file with sed using Bash Linux.

A
sed '2a\new line' file
Replace Text Between Two Patterns:
sed '/start/,/end/s/old/new/' file
Replace Text in a File and Save to a New File:
sed 's/old/new/g' input.txt > output.txt
Delete All Lines Containing a Pattern:
sed '/pattern/d' file
Print Lines Matching a Pattern:
sed -n '/pattern/p' file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does Linux Bash command “crontab” do?

A

The crontab command in Linux is used to schedule tasks to run at specified times or intervals. These tasks are called “cron jobs” and are defined in a file known as the crontab file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does Linux Bash command “uniq” do?

A

Used to filter out or report duplicate lines in a sorted file or input.

This command reads from filename and outputs unique lines, filtering out adjacent duplicate lines.

uniq filename
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Prefixes for each line with the number of occurrences using Bash Linux.

A
uniq -c filename
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Show Only Duplicate Lines using Bash Linux.

A
uniq -d filename
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Show Only Unique Lines using Bash Linux.

A
uniq -u filename
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the Linux Bash command “paste” do?

A

Used to merge lines of files horizontally (side-by-side).

paste file1 file2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the Linux Bash command “seq” do?

A

Used to generate a sequence of numbers. It can be used to create lists of numbers.

paste <(seq 1 5) <(seq 11 15) <(seq 21 25)
1	11	21
2	12	22
3	13	23
4	14	24
5	15	25
seq [options] FIRST LAST
seq 1 5
1
2
3
4
5
seq 1 2 9
1
3
5
7
9
seq -s "," 1 5
1,2,3,4,5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the Linux Bash command “nl” do?

A

Used to number the lines of a file.

nl filename

Output:
     1  apple
     2  banana
     3  cherry
     4  date
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to write a number the lines of a file using Linux Bash?

A

nl filename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the Linux Bash command “tac” do?

A

Used to concatenate and print files in reverse, line by line.

apple
banana
cherry
date

tac example.txt

date
cherry
banana
apple
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the Linux Bash command “column” do?

A

Used to format text into columns. It takes input from standard input or a specified file and organizes the data into neatly aligned columns.

apple 1
banana 2
cherry 3
date 4

column data.txt

apple  1
banana 2
cherry 3
date   4
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the Linux Bash command “colrm” do?

A

Used to remove columns from a file or standard input.

colrm start
This command removes all characters starting from column start to the end of each line.
colrm start end
This command removes all characters from column start to column end inclusive.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What does the Linux Bash command “od” do?

A

Used to display data in various binary formats, such as octal, hexadecimal, decimal, and ASCII.

od example.txt
0000000 110401 114503 115510 054040 127507 162154 100041 0000016

The default output displays the data in octal format.
Hexadecimal Output
od -x example.txt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What does the Linux Bash command “split” do?

A

Used to split a file into smaller parts.

Split File into Parts with 2 Lines Each:
split -l 2 example.txt
Split File into Parts of 20 Bytes Each:
split -b 20 example.txt
19
Q

What does the Linux Bash command “egrep” do?

A

used to search for patterns in files or standard input using extended regular expressions (EREs) (more powerful and flexible pattern matching)

Search for Lines Ending with "berry":
egrep 'berry$' example.txt
20
Q

What does the Linux Bash command “awk” do?

A

Powerful text processing tool that allows you to manipulate and analyze data in text files.

awk 'pattern { action }' [file ...]
Print the Entire File:
awk '{ print }' example.txt
21
Q

What does the Linux Bash command “comm” do?

A

Used to compare two sorted files line by line. This command is useful for finding differences and similarities between two datasets.

comm [options] file1 file2
vergleicht zwei alphabetisch sortiere Dateien:
1
		    2
		    3
		    4
	5
-2 kann bespielsweise die Darstellung der zweiten Spate unterdrückt werden.
comm -2 <(seq 1 4) <(seq 2 5)
1
    	2
	    3
    	4
22
Q

What does the Linux Bash command “diff” do?

A

used to compare files line by line. It identifies differences between two files or directories and outputs the changes necessary to make the files or directories identical.

file1.txt:
apple
banana
cherry
date

file2.txt:
apple
banana
citrus
date
elderberry

diff file1.txt file2.txt
3c3
< cherry
---
> citrus
4a5
> elderberry
23
Q

What does the Linux Bash command “patch” do?

A

A patch file typically contains differences between two versions of a file or a set of files, and the patch command reads this file and applies those changes to the original files, effectively updating them to the new versions.

24
Q

What does the Linux Bash command “uname -a” do?

A

Used to display comprehensive information about the system

uname -a
Linux platon 5.4.0-87-generic #98~18.04.1-Ubuntu SMP Wed Sep 22 10:45:04 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

1 Kernel Name
2 Node Name
3 Kernel Release
4 Kernel Version
5 Machine
6 Processor
7Hardware Platform
8 Operating System

25
Q

What does the Linux Bash command “uptime” do?

A

Provides information about how long the system has been running, the number of users currently logged in, and the system load averages for the past 1, 5, and 15 minutes.

uptime1
10:52:07 up 20 days,  2:00,  1 user,  load average: 0,09, 0,10, 0,34
26
Q

What does the Linux Bash command “ps” do?

A

Used to display information about the currently running processes on the system. current processes, IDs (PIDs), user IDs, CPU usage, memory usage, and more.

27
Q

What does the Linux Bash command “top” do?

A

Powerful utility for real-time system monitoring. It provides a dynamic view of the system’s running processes, updating periodically.

28
Q

Powerful utility for real-time system monitoring using Linux Bash

A

top

29
Q

What does the Linux Bash command “kill” do?

A

Used to send signals to processes, usually to terminate or control them.

30
Q

What does the Linux Bash command “pgrep” do?

A

Used to search for processes based on their name and other attributes. It returns the process IDs (PIDs) of the processes that match the given criteria.

31
Q

How to search for processes based on their name and other attributes using Linux Bash

A

pgrep

32
Q

What does the Linux Bash command “pstree” do?

A

display a tree of processes

33
Q

What does the Linux Bash command “vmstat” do?

A

report virtual memory statistics

34
Q

What does the Linux Bash command “tload” do?

A

graphic representation of system load average

35
Q

What does the Linux Bash command “nice” do?

A

Used to run a command with a modified scheduling priority. By adjusting the priority, you can influence how the kernel allocates CPU time to the process.

36
Q

Linux Bash “ps” command

A

Zeigt nur alle laufende Prozesse in der laufende Terminalsession

37
Q

Linux Bash “ps -u” command

A

Zeigt alle eigene Prozesse (User)

38
Q

What does ‘colrm -87’ command do

A

Zeigt nur die erste 87 Zeichen jeder Zeile

39
Q

Wie kannst du den Inhalt einer Textdatei namens “input.txt” in eine Variable namens “content” einlesen und anschließend den Inhalt der Variable auf der Konsole ausgeben?

A
content=$(cat input.txt)
echo "$content"
40
Q

Wie kannst du mit einem Bash-Befehl die zweite und dritte Spalte einer durch Kommas getrennten CSV-Datei namens “data.csv” extrahieren und auf der Konsole ausgeben?

A
awk -F',' '{print $2, $3}' data.csv
41
Q

Wie kannst du in der Bash den PID eines laufenden Prozesses namens “myapp” finden und diesen Prozess dann beenden?

A
pid=$(pgrep myapp)
kill $pid
42
Q

Wie würdest du alle laufenden Prozesse eines Benutzers namens user123 anzeigen?

A
ps -u user123

oder

pgrep -u user123
43
Q

Wie extrahierst du die dritte Spalte aus einer Datei namens records.csv, wobei die Spalten durch Kommas getrennt sind?

A
awk -F, '{print $3}' records.csv