Using Essential tools Flashcards

1
Q

What is a shell?

A

The shell is the default working environment for a Linux administrator. It is the environment where users and administrators enter commands that are executed by the operating sys§tem. Different shells for Linux are available, but Bash is the most common shell.

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

what is the syntax of a command in linux?

A

the command, its options, and its arguments

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

what is an argument in linux command?

A

it refers to anything that the command addresses, so anything you put after the command is an argument (including the options)

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

what is an option in linux command?

A

To modify the behavior of the command, you can use options. Options are a part of the program code, and they modify what the command is doing. For instance, when you use the -l option with the ls command, a long list- ing of filenames and properties is displayed.

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

what is the purpose of shell?

A

The purpose of the Linux shell is to provide an environment in which commands can be executed

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

what are the three types of commands in linux?

A

Aliases
Internal commands
external commands

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

what is alias in linux?

A

An alias is a command that a user can define as needed.
To define an alias, use alias newcommand=’oldcommand’, as in the default alias ll=’ls -l –color=auto’ that has already been created on your system

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

How to define an alias?

A

To define an alias, use alias newcommand=’oldcommand’, as in the default alias ll=’ls -l –color=auto’ that has already been created on your system

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

what is internal command?

A

is a command that is a part of the shell itself and, as such, doesn’t have to be loaded from disk separately.

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

what is external command?

A

is a command that exists as an executable file on the disk of the computer. Because it has to be read from disk the first time it is used, it is a bit slower.

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

How to determine if the command is internal or external?

A

use “type” followed by the command
eg. type ls
To find out whether a command is a Bash internal or an executable file on disk, you can use the type command.

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

What happens when user runs a command?

A

When a user executes a command, the shell first looks to determine whether it is an internal command; if it is not, it looks for an executable file with a name that matches the command on disk.

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

what is $PATH variable used for?

A

To look up external commands
This variable defines a list of directories that is searched for a matching filename when a user enters a command

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

To find out which exact command/executable the shell will be using, what command to use?

A

which
eg which ls

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

how to find from where is this ls command coming?

A

type which ls to find out where the shell will get the ls command from?

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

Is the current directory present in the $PATH variable?

A

for security reasons the current directory is not in the $PATH variable and Linux does not look in the current directory to see whether a specific command is available from that directory.

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

Is $PATH variable different for different users?

A

The $PATH variable can be set for specific users, but in general, most users will be using the same $PATH variableh

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

which command can be used to know the time it took to complete this command

A

time
eg time ls

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

what is STDOUT

A

standard output. Usually monitor is the standard output

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

The shell also has default destinations to send error messages to and to accept input. what are these?

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

default destination for standard input?

A

keyboard

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

default destination for standard output?

A

monitor

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

default destination for standard error?

A

monitor

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

File descriptor number for standard input? STDIN

A

0

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

File descriptor number for standard output? STDOUT

A

1

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

File descriptor number for standard output? STDERR?

A

2

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

when you use a command in linux how does reading and writing work?

A

Programs started from the command line have no idea what they are reading from or writing to. They just read from what the Linux kernel calls file descriptor 0 if they want to read from standard input, and they write to file descriptor number 1 to display non-error output (also known as “standard output”) and to file descriptor 2 if they have error messages to be output. By default, these file descriptors are con- nected to the keyboard and the screen. If you use redirection symbols such as <, >, and |, the shell connects the file descriptors to files or other commands

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

Is file descriptor number 1 to display non-error output

A

Yes , True

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

Is file descriptor number 2 to display error output

A

Yes True

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

where are these file descriptors connected by default? and what happens if we use re-direction or pipe with these file descriptors?

A

By default, these file descriptors are connected to the keyboard and the screen. If you use redirection symbols such as <, >, and |, the shell connects the file descriptors to files or other commands.

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

what is the redirector that is used to re-direct the STDOUT to a file?

A

> eg ls -l > test.txt

32
Q

what is the redirector that is used to re-direct the STDERR to a file?

A

2>
eg. ls -l 2> test_err.txt

33
Q

what is this redirector used for? 2>&1?

A

Redirects STDERR to the same destination as STDOUT

34
Q

what is a device file in linux?

A

A device file on Linux is a file that is used to access specific hardware. Your hard disk, for instance, can be referred to as /dev/sda, the console of your server is known as /dev/console or /dev/tty1

35
Q

which device file to use if we you want to discard a command’s output

A

/dev/null
eg.
ls -l > /dev/null

36
Q

what is pipe | used for ?

A

a pipe can be used to catch the output of one command and use that as input for a second command

37
Q

can you give an example of using pipe? what happens when using pipe?

A

If a user runs the command ls, for instance, the output of the command is shown onscreen, because the screen is the default STDOUT.
If the user uses ls | less, the commands ls and less are started in parallel. The standard output of the ls command is connected to the standard input of less

38
Q

command to know your current directory?

A

pwd

39
Q

how to redirect the STDOUT to the null device

A

use /dev/null
eg. ls > /dev/null
> redirector is used to redirect the STDOUT so, and /dev/null is the null device

40
Q

I am using this command
ls ilwehgi > /dev/null
but there is no file/directory by the name ilwehgi. what will happen?

A

> is the redirector used to redirect the STDOUT .
/dev/null - here we are redirecting the STDOUT to /dev/null
However here there will not be any output as this file/directory does not exists. There will be an error saying “no such file or directory” Now this error is sent to STDERR, and default destination for STDERR is also monitor so the error is displayed on screen

41
Q

I am using this command
ls ilwehgi 2> /dev/null
but there is no file/directory by the name ilwehgi. Will I see the error on the screen?

A

No.you will no longer see the error message.
because “2>” here 2 is the file descriptor used for STDERR and > is the redirector used to redirect the error to /dev/null which is null device.
So we are re-directing the STDERR from being displayed on screen to a null device.

42
Q

I am using this command
ls ilwehgi Documents 2> /dev/null
but there is no file/directory by the name ilwehg.
What will happen

A

This shows the name of the
Documents folder in your home directory while hiding the error message that ilwehgi file/directory does not exists

43
Q

ls ilwehgi Documents 2> /dev/null > output
I am using above command. but there is no file/directory by the name ilwehg.
What will happen

A

In this command, you still write the error message to /dev/null while sending STDOUT to a file with the name output that will be created in your home directory.

44
Q

what is the .bash_history file?

A

When a shell session is closed, the history of that session is updated to the .bash_history file

45
Q

Where is the .bash_history file created?

A

in the home directory of the user who started a specific shell session

46
Q

what are the different ways of working with bash history?

A
  1. Use history command
  2. use ctrl+r which opens a prompt where you can do backward searches
  3. !number to execute the command with specific number from the history
  4. !sometext, to execute the command that last starts with sometext
47
Q

what is “history -c”

A

to clear the current session history. Commands from this session won’t be written to the history file when you exit the current session

48
Q

If you want to remove the complete bash history?

A

type “history -w” immediately after using “history -“

49
Q

what are the different modes in vim or vi editor?

A

command mode and input mode
and visual mode

50
Q

what can you do in command mode in vi or vim editor?

A

you can just enter a command and you cannot change the contents of a text file. To change thee content go to insert mode , press i

51
Q

How to switvh from input mode to command mode again in vi editor?

A

press ESC key

52
Q

“i” or “a” in vi editor command mode?

A

Switches from command mode to input mode at (i) or after (a) the current cursor position

53
Q

“o” in vi editor command mode?

A

Opens a new line below the current cursor position and goes to input mode.

54
Q

“:wq” in vi editor in command mode?

A

Writes the current file and quits.

55
Q

“:q!” in vi editor in command mode?

A

Quits the file without applying any changes. The ! forces the command to do its work. Only add the ! if you really know what you are doing.

56
Q

“:w filename” in command mode vi editor

A

Writes the current file with a new filename

57
Q

“dd” and “yy” in command mode in vi editor?

A

Deletes the current line.
copies the current line

58
Q

“p” in comomand mode in vi editor?

A

Pastes the current selection.

59
Q

“v” in command mode in vi editor?

A

Enters visual mode, which allows you to select a block of text using the arrow keys. Use “d” to cut the selection or “y” to copy it.

60
Q

“u” in command mode in vi editor?

A

Undoes the last command

61
Q

ctrl+r in command mode in vi editor?

A

Redoes the last undo

62
Q

“gg” in command mode in vi editor?

A

Goes to the first line in the document.

63
Q

“G” in command mode in vi editor?

A

Goes to the last line in the document.

64
Q

“/text” in command mode in vi editor?
also “?text”

A

Searches for text from the current cursor position forward
“?text” searches for the text from the current position backward

65
Q

^ in command mode in vi editor?

A

Goes to the first position in the current line.

66
Q

$ in command mode in vi editor?

A

Goes to the last position in the current line.

67
Q

”:%s/old/new/g” in command mode of vi editor?

A

Replaces all occurrences of old with new

68
Q

“!ls” in command mode in vi editor?

A

Adds the output of ls (or any other command) in the current file

69
Q

what is the environment in linux?

A

shell

70
Q

what are environment variables?

A

environment consists of variables that define the user environment, such as the $PATH variable

71
Q

what are variables in environment in linux?

A

variables are fixed names that can be assigned dynamic values. eg. $PATH and $LANG

72
Q

when is a environment created for a user?

A

when a user logs in. The environment creation happens based on four different configuration files:

/etc/profile: This is the generic file that is processed by all users upon login.
/etc/bashrc: This file is processed when subshells are started.
~/.bash_profile: In this file, user-specific login shell variables can be defined.
~/.bashrc: In this user-specific file, subshell variables can be defined.

73
Q

what is this file /etc/profile?

A

This is the generic file that is processed by all users upon login.

74
Q

/etc/bashrc , what is this file

A

This file is processed when subshells are started

75
Q

what is this file - “~/.bash_profile”

A

In this file, user-specific login shell variables can be defined

76
Q

what is this file “~/.bashrc”

A

In this user-specific file, subshell variables can be defined