Linux Flashcards

1
Q

What is a Shell?

A

It is a program that exposes the operating system. For example bash (Bourne Again Shell). It is usually interacted with via terminal (a shell prompt) by keyboard input.

Dash, ash, are all types of shell.

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

How to eliminate duplicate lines in a linux file?

A

cat file.txt | sort –unique

Also

cat file.txt | sort | uniq

Also works, but is more verbose.

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

What are the standard streams in a Linux system?

A

The standard streams are three interconnected input and output communication channels.

The two output streams are stdout and stderr. They are represented as files at /dev/stdout and /dev/stderr respectively. While stdout is meant to be the default destination text output from the shell, while stderr receives error output from the shell. Of course there can be exceptions. The file descriptor for stdout is 1 and for stderr is 2.

The input stream is stdin, represented by a file at /dev/stdin. Not all programs require input streams. The file descriptor for stdin is 0.

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

How to send error stream to the output stream?

A

On bash: 2>&1

2 is the file descriptor for stderr
1 is the file descriptor for stdout

> is redirect; for example command 2> file would redirect stderr to a file
& is necessary to identify 1 as a file descriptor and not as a file named 1

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

What does true && false || true evaluate to?

A

It evaluates to true.

(true && false) evaluates to false
(false || true) evaluates to true

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

Given aa && bb || cc; which commands are executed given different exit codes?

A

Either:

  • aa (if a is false)
  • aa, bb (if a is true and b is true)
  • aa, bb, cc (if a is true and b is false)

In summary:

  • && is AND; only executes the second command if first is true
  • || is AND; only executes the second command if first is false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly