Ch 2 Using Essential Tools Flashcards

(149 cards)

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
How would you redirect a command's input to being from a file and not the keyboard?
Cmd < file ./myscript < myfileforscript.txt
26
What's the difference between using a | for output vs STDOUT redirection with > ?
I think it's that a pipe redirects output to another command, whereas > is more for redirecting output to a file?
27
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?
Using I/O redirection. This is why I/O redirection exists.
28
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...
Connect to keyboard and monitor.
29
Stderr by default goes to...
File descriptor 2
30
These characters connect file descriptors to files and commands in the shell
> < and |
31
What does > (same as 1>) do?
Redirects STDOUT. If to a file, it overwrites the file's original contents
32
What does >> (same as 1>>) do to STDOUT?
Redirects it in append mode. If output goes to a file, output appends to the existing file content
33
What command clears or wipes a file of content?
/Dev/null > file
34
What does 2> do?
Redirects stderr. Can redirect to a file
35
What does 2>&1 do?
Redirects stderr to the same destination as stdout. Stderr output has to be redirected with stdout redirection?
36
Example of redirecting stderr with stdout
Ls whuhiu > errout 2>&1
37
What does the character < (same as 0<) do?
Redirects stdin (usually a file)
38
What can be used to replace the default destinations for stdout, stdin, and stderr?
Files, and also device files
39
What is a device file?
A file that is used to access specific hardware
40
Example device files...
/dev/sda - hard disk /dev/tty1 or /dev/console for the server console /dev/null to discard I/O
41
Accessing device files needs what user level of privilege?
Root
42
what key do you press in vim to switch to input mode with the cursor exactly at your position?
i
43
what key do you press in vim to switch to input mode with the cursor directly after your current cursor position?
a
44
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?
o
45
What vim command deletes the current line and places its contents into memory?
dd
46
Bash's default configuration saves how many of the last commands?
1000
47
When a shell session closes, what happens to the shell history?
It updates the history file, .bash_history, in the home directory of the user of the shell session
48
What happens to shell memory before the shell is closed and written to .bash_history?
It's held in memory
49
What command shows bash history?
History
50
What keyboard shortcut lets you type a word and match it with a string in the command history?
Ctrl + R
51
How do you get to a specific line number from history?
!number
52
How do you delete a command from history?
History -d number This also renumbers all the history commands.
53
What command will execute a command from history containing a word starting with something you just typed?
!sometext
54
When might it be necessary to delete bash history?
If a password were typed into clear text
55
How do you delete command history entirely?
History -c
56
When you use the clear history command (history -c) does it save anything from your current session when it ends?
No
57
How do you wipe history of your current session AS WELL AS the .bash_history file?
History -c followed by history -d
58
What are the different vim modes?
Command mode Input mode Visual mode
59
Refreshes a file in vim while you're in it
:edit
60
How to remove line numbering in vim
:set nonu or :set nonumber
61
How to number the lines in vim
:set nu or :set number
62
forward search in vim, and for specific text
/text
63
backward search in vim
?text
64
what vim command would you use inside vim to rename the file you're in? (Save as..)
:w newfilename
65
can the $PATH variable be set for specific users?
yes, but generally, most users use the same. However, the root user has its own access
66
how do you set an environmental for just your current shell session?
by entering it on the command line instead of a configuration file
67
what command lets you see all your current environmental variables?
env
68
what file shows all current environmental variables?
/etc/environment
69
what's the template for setting an environmental variable? (In a file, not on command line)
VAR='/path/to/var'
70
/dev/sda is what?
your hard disk
71
/dev/tty1 is what?
usually the console of your server
72
/dev/console is what?
the console of your server
73
What is /dev/null often used for?
To discard the output of a command (can also be used to wipe a file like IV has done) cat /dev/null > filename
74
What vim command copies (yanks) the current line?
yy
75
What pastes whatever contents are in memory, in vim?
p (paste was was dd-ed or yy-ed)
76
What keyboard character switches vim to visual mode?
v
77
What keyboard vim character does undo for the last action?
esc+u or :u
78
What redos the last action in vim? (but only once)
ctrl+r
79
What keyboard characters move your cursor to the very beginning of a file in vim?
gg
80
What keyboard characters move your cursor to the very end of a file in vim?
G
81
What keyboard character moves you to the first character in the line, in vim?
esc+^
82
What keyboard character moves you to the last character in the line, in vim?
esc+$
83
What adds the output of ls or any other command into the current file, in vim?
!ls or !command (I actually found that it brought this up but didn't actually put it in the file for some reason)
84
Replace all occurrences of old with new, in vim
:%s/old/new/g the g means do it globally, or for every instance, ad the %s means substitute
85
What is the environment for a shell? (shell environment)
It consists of variables that define the user environment, such as the $PATH variable
86
In the context of a shell environment, what is a variable?
fixed names that can be assigned dynamic values
87
Explain what the environmental variable $LANG is for
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
Can environmental variables be used in scripts and programs?
yes
89
True or false, can different users have different shell environments, and thus different environmental variables?
true
90
name some common environmental variables
$MAIL $PATH $PWD $LANG $HISTCONTROL $SHLVL (shell level) $HOME $LOGNAME $LESSOPEN $_ $OLDPWD
91
How can you find the value of an environmental variable from the command line?
env to show all of them
92
When are shell environments created?
When a user logs in
93
When the shell environment is created, what file determines how it is made?
/etc/profile - global scope /etc/bashrc - global scope ~/.bashrc - local user scope ~/.bash_profile - local user scope
94
shell environment config file for all users upon login (generically)
/etc/profile
95
shell environment config file for when subshells are made
/etc/bashrc
96
shell environment config file for user-specific login shells
~/.bash_profile
97
shell environment config file for subshells on a user-specific level
~/.bashrc
98
What is the difference between a login shell and a subshell?
Login Shell: It's the shell that's invoked when you log in through a terminal or SSH. It's responsible for initializing the terminal environment and setting up your user's preferences. It reads and executes configuration files like .profile and sometimes .bash_profile. Subshell: It's a new shell process spawned by the main shell. It's used to execute commands or scripts within a separate environment. Any changes made within the subshell's environment (like setting variables) are not automatically propagated to the main shell. Subshells can be created by running scripts, using parentheses to group commands, or invoking a new shell within a script.
99
What configuration file determines what is displayed after you login? (like an information banner)
/etc/motd and /etc issues files
100
How can sysadmins take advantage of the /etc/motd file?
They can use it to inform users of an issue or security policy
101
Other than /etc/motd, what other way can sysadmins inform users of issues and security policies and such?
/etc/issue
102
The contents of what file display before you login in a text console interface?
/etc/issue
103
What file can be used to give users login instructions before they login?
/etc/issue
104
What command will help you learn more about a command's syntax and usage?
man
105
What's a more succint version of providing what the man command provides?
the --help option flag (gives you all possible options for a command)
106
A man page includes what sections?
An Examples area and a See Also area (related man pages)
107
What keyboard key will take you to the end of the man page?
G
108
What part of the man page are the examples and the See Also?
the end
109
How can you find examples in a man page?
/example
110
How can you find the man page you want? (search the mandb man database)
apropos and man -k
111
What's a weakness of using man -k for finding a man page?
The text you use to search, e.g. "man -k partition" will only find commands with that term (partition) in its summary
112
What command could be substituted for man -k?
apropos
113
What other system provides info about command usage, other than man pages?
the info system
114
When do you use the info system instead of the man page?
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
The info system for a command is also called what?
Texinfo manual
116
How do you pull up the info page for a command?
pinfo or info
117
How are pinfo and info different?
pinfo has a menu and easier navigation
118
How are info pages organized?
like web pages, that is to say, hierarchical
119
What are the navigation shortcuts for an info page, for next, previous, and up (up in the hierarchy/file/directory tree)
n, p, u
120
What denotes a menu item in an info page?
An * (*** underline?)
121
To advance in an info page (drill down into file/directory/page tree) what do you use?
arrow keys
122
What is a third source of info on commands beside man pages and info pages (and not the --help flag)?
/usr/share/doc
123
How is /usr/share/doc different from man and info pages?
Tends to be better for services and systems (something more complex than a singular command)
124
What services have very useful /usr/share/doc pages?
rsyslog bind Kerberos OpenSSL
125
126
127
128
129
130
131
132
133
134
135
command that shows you who is logged in
who
136
command that tells you how long the system has been running
uptime
137
command that shows you the full patch of a command
which
138
a command that helps you find related files for a command
whereis (like path to binary and the docs.../usr/bin, /usr/share/doc...)
139
a command that shows you who is logged in and what they're doing
w (the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. The following entries are displayed for each user: login name, the tty name, the remote host, login time, idle time, JCPU, PCPU, and the command line of their current process. The JCPU time is the time used by all processes attached to the tty. It does not include past background jobs, but does include currently running background jobs. The PCPU time is the time used by the current process, named in the "what" field.)
140
141
If a .bash_profile file exists in a user home directory, what does that mean for the /etc/profile?
It will be overrided by the .bash_profile local file
142
When is the user specific ~/.profile ir .bash_profile file invoked?
Only when you first login to an acct. If there is no user specific file, it uses the /etc/profile file, otherwise it will use its local profile fil
143
When is the .bash or .bashrc file called?
Unlike profile, which is only called at first login, bash is called every time a terminal is opened
144
What command can prompt a new LOGIN (not subshell) shell?
Bash -l
145
If the profile file gets corrupted or lost, where can a new one be sourced from?
/etc/skel
146
Is a bashrc or .bash file invoked in a login shell?
No
147
Is a new session created by sshing to a user considered a login shell?
It is not, and therefore it won't source .profile
148
What shell file is invoked in shells where you don't want child processes/subshells to inherit the environment?
.profile or .bash_profile, because a .bashrc won't be inherited .profile and .bash_profile ARE inherited by subshells/child processes .bashrc files do not get inherited in subshells/child processes
149
Which file is shell agnostic?
.profile