Ch 2 Using Essential Tools Flashcards

1
Q

How do you create an alias?

A

alias newcommand=’oldcommand’

Ex:
Alias ll=’ls -l –color=auto’

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

Are commands or aliases executed first?

A

Aliases are, unless a full path for a command is used, e.g., /usr/bin/reboot

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

What is an internal vs external command?

A

Internal command is a PART of the shell and doesn’t have to be loaded from disk separately

An external command exists as an executable file on the disk of the computer (slower to load on first use)

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

When a command is run, the shell first looks to see if its internal. If not, where does it look for external commands?

A

Looks on the disk for a similar named command that is executable

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

What command will tell you if a command is internal or external?

A

Type

E.g. type pwd

This also reveals if it’s an alias

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

How can external commands be found by the shell?

A

The $PATH variable

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

How does the $PATH variable work?

A

It defines a list of directories that can be 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
8
Q

What does the which command do?

A

Figures out which command the shell will use

E.g. which ls - where will ls command come from? (The external directory that an external command will come from?) But type is a stronger command, since it works for internal commands and aliases

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

Why doesn’t the $PATH variable include the current directory?

A

For security reasons

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

What must prepend a command if you are trying to execute a command that is in your current directory but NOT in the $PATH?

A

./

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

What does ./ mean?

A

The . is for current directory, and the / is for the rest

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

When does ./ become necessary for execution? An example case?

A

For a homeade script you wrote in your working directory

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

Can the $PATH be user specific?

A

Yes, most users will use the same $PATH. The root user is an exception.

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

Which I/O goes to the computer monitor, and is also the default destination?

A

STDOUT

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

What is the default outout destination errors in the shell?

A

STDERR

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

Default shell source for input?

A

STDIN

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

Default destination for STDERR?

A

Computer monitor

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

Default destination for STDIN?

A

Computer keyboard

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

What character is used to redirect the destination for STDIN?

A

< (same as 0<)

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

What is the File Descriptor Number for STDIN?

A

0

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

What is the File Descriptor Number for STDOUT?

A

1

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

What is the character for redirecting STDOUT?

A

> (same as 1>)

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

What is the character for redirecting STDERR?

A

2>

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

What is the File Descriptor Number for STDERR?

A

2

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

How would you redirect a command’s input to being from a file and not the keyboard?

A

Cmd < file

./myscript < myfileforscript.txt

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

What’s the difference between using a | for output vs STDOUT redirection with > ?

A

I think it’s that a pipe redirects output to another command, whereas > is more for redirecting output to a file?

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

How do you redirect I/O when it’s coming from a background command, a command from a different terminal session, or a monitor? And what if there’s no keyboard to accept input from?

A

Using I/O redirection. This is why I/O redirection exists.

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

A command reads from file descriptor 0 for stdin, and writes to file descriptor 1 for non error output. By default, std in and stdout…

A

Connect to keyboard and monitor.

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

Stderr by default goes to…

A

File descriptor 2

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

These characters connect file descriptors to files and commands in the shell

A

> < and |

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

What does > (same as 1>) do?

A

Redirects STDOUT. If to a file, it overwrites the file’s original contents

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

What does&raquo_space; (same as 1») do to STDOUT?

A

Redirects it in append mode. If output goes to a file, output appends to the existing file content

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

What command clears or wipes a file of content?

A

/Dev/null > file

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

What does 2> do?

A

Redirects stderr. Can redirect to a file

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

What does 2>&1 do?

A

Redirects stderr to the same destination as stdout. Stderr output has to be redirected with stdout redirection?

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

Example of redirecting stderr with stdout

A

Ls whuhiu > errout 2>&1

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

What does the character < (same as 0<) do?

A

Redirects stdin (usually a file)

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

What can be used to replace the default destinations for stdout, stdin, and stderr?

A

Files, and also device files

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

What is a device file?

A

A file that is used to access specific hardware

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

Example device files…

A

/dev/sda - hard disk
/dev/tty1 or /dev/console for the server console
/dev/null to discard I/O

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

Accessing device files needs what user level of privilege?

A

Root

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

what key do you press in vim to switch to input mode with the cursor exactly at your position?

A

i

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

what key do you press in vim to switch to input mode with the cursor directly after your current cursor position?

A

a

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

what key do you press in vim to switch to input mode that starts the cursor in a new line below the current cursor position?

A

o

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

What vim command deletes the current line and places its contents into memory?

A

dd

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

Bash’s default configuration saves how many of the last commands?

A

1000

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

When a shell session closes, what happens to the shell history?

A

It updates the history file, .bash_history, in the home directory of the user of the shell session

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

What happens to shell memory before the shell is closed and written to .bash_history?

A

It’s held in memory

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

What command shows bash history?

A

History

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

What keyboard shortcut lets you type a word and match it with a string in the command history?

A

Ctrl + R

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

How do you get to a specific line number from history?

A

!number

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

How do you delete a command from history?

A

History -d number

This also renumbers all the history commands.

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

What command will execute a command from history containing a word starting with something you just typed?

A

!sometext

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

When might it be necessary to delete bash history?

A

If a password were typed into clear text

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

How do you delete command history entirely?

A

History -c

56
Q

When you use the clear history command (history -c) does it save anything from your current session when it ends?

57
Q

How do you wipe history of your current session AS WELL AS the .bash_history file?

A

History -c followed by history -d

58
Q

What are the different vim modes?

A

Command mode
Input mode
Visual mode

59
Q

Refreshes a file in vim while you’re in it

60
Q

How to remove line numbering in vim

A

:set nonu or :set nonumber

61
Q

How to number the lines in vim

A

:set nu or :set number

62
Q

forward search in vim, and for specific text

63
Q

backward search in vim

64
Q

what vim command would you use inside vim to rename the file you’re in? (Save as..)

A

:w newfilename

65
Q

can the $PATH variable be set for specific users?

A

yes, but generally, most users use the same. However, the root user has its own access

66
Q

how do you set an environmental for just your current shell session?

A

by entering it on the command line instead of a configuration file

67
Q

what command lets you see all your current environmental variables?

68
Q

what file shows all current environmental variables?

A

/etc/environment

69
Q

what’s the template for setting an environmental variable?

A

VAR=’/path/to/var’

70
Q

/dev/sda is what?

A

your hard disk

71
Q

/dev/tty1 is what?

A

usually the console of your server

72
Q

/dev/console is what?

A

the console of your server

73
Q

What is /dev/null often used for?

A

To discard the output of a command (can also be used to wipe a file like IV has done)

74
Q

What vim command copies (yanks) the current line?

75
Q

What pastes whatever contents are in memory, in vim?

A

p (paste was was dd-ed or yy-ed)

76
Q

What keyboard character switches vim to visual mode?

77
Q

What keyboard in character does undo for the last action?

A

esc+u or :u

78
Q

What redos the last action in vim? (but only once)

79
Q

What keyboard characters move your cursor to the very beginning of a file in vim?

80
Q

What keyboard characters move your cursor to the very end of a file in vim?

81
Q

What keyboard character moves you to the first character in the line, in vim?

82
Q

What keyboard character moves you to the last character in the line, in vim?

83
Q

What adds the output of ls or any other command into the current file, in vim?

A

!ls or !command (I actually found that it brought this up but didn’t actually put it in the file for some reason)

84
Q

Replace all occurrences of old with new, in vim

A

:%s/old/new/g

the g means do it globally, or for every instance, ad the %s means substitute

85
Q

What is the environment for a shell? (shell environment)

A

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

86
Q

In the context of a shell environment, what is a variable?

A

fixed names that can be assigned dynamic values

87
Q

Explain what the environmental variable $LANG is for

A

can be set to en_US.UTF-8
this means you can work in the english language with the settings that are the most commond for English ( like time and date)

88
Q

Can environmental variables be used in scripts and programs?

89
Q

True or false, can different users have different shell environments, and thus different environmental variables?

90
Q

name some common environmental variables

A

$MAIL
$PATH
$PWD
$LANG
$HISTCONTROL
$SHLVL (shell level)
$HOME
$LOGNAME
$LESSOPEN
$_
$OLDPWD

91
Q

How can you find the value of an environmental variable from the command line?

A

env to show all of them, or echo $ENVVAR to see

92
Q

When are shell environments created?

A

When a user logs in

93
Q

When the shell environment is created, what file determines how it is made?

A

/etc/profile
/etc/bashrc
~/.bashrc
~/.bash_profile

94
Q

shell environment config file for all users upon login (generically)

A

/etc/profile

95
Q

shell environment config file for when subshells are made

A

/etc/bashrc

96
Q

shell environment config file for user-specific login shells

A

~/.bash_profile

97
Q

shell environment config file for subshells on a user-specific level

98
Q

What is the difference between a login shell and a subshell?

A

login shell - first shell that is opened after a user logs in
subshell - created when running a script form the login shell (for the script to run in )

99
Q

What configuration file determines what is displayed after you login? (like an information banner)

A

/etc/motd and /etc issues files

100
Q

How can sysadmins take advantage of the /etc/motd file?

A

They can use it to inform users of an issue or security policy

101
Q

Other than /etc/motd, what other way can sysadmins inform users of issues and security policies and such?

A

/etc/issue

102
Q

The contents of what file display before you login in a text console interface?

A

/etc/issue

103
Q

What file can be used to give users login instructions before they login?

A

/etc/issue

104
Q

What command will help you learn more about a command’s syntax and usage?

105
Q

What’s a more succint version of providing what the man command provides?

A

the –help option flag (gives you all possible options for a command)

106
Q

A man page includes what sections?

A

An Examples area and a See Also area (related man pages)

107
Q

What keyboard key will take you to the end of the man page?

108
Q

What part of the man page are the examples and the See Also?

109
Q

How can you find examples in a man page?

110
Q

How can you find the man page you want? (search the mandb man database)

A

apropos and man -k

111
Q

What’s a weakness of using man -k for finding a man page?

A

The text you use to search, e.g. “man -k partition” will only find commands with that term (partition) in its summary

112
Q

How are man -k and apropos different?

A

they aren’t

113
Q

What other system provides info about command usage, other than man pages?

A

the info system

114
Q

When do you use the info system instead of the man page?

A

It depends. Some commands have short man pages and most of their info is in the info page. If this is the case, the “See Also” part of a man page will say this.

115
Q

The info system for a command is also called what?

A

Texinfo manual

116
Q

How do you full up the info page for a command?

A

pinfo or info

117
Q

How are pinfo and info different?

A

pinfo has a menu and easier navigation

118
Q

How are info pages organized?

A

like web pages, that is to say, hierarchical

119
Q

What are the navigation shortcuts for an info page, for next, previous, and up (up in the hierarchy/file/directory tree)

120
Q

What denotes a menu item in an info page?

A

An * (*** underline?)

121
Q

To advance in an info page (drill down into file/directory/page tree) what do you use?

A

arrow keys

122
Q

What is a third source of info on commands beside man pages and info pages (and not the –help flag)?

A

/usr/share/doc

123
Q

How is /usr/share/doc different from man and info pages?

A

Tends to be better for services and systems (something more complex than a singular command)

124
Q

What services have very useful /usr/share/doc pages?

A

rsyslog
bind
Kerberos
OpenSSL