LX0-101 Flashcards

1
Q

What are the main user configuration files for bash?

A

~/.bashrc and ~/.profile

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

What are the main global configuration files?

A

/etc/bash.bashrc and /etc/profile

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

How to view available variables in the environment?

A

env

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

How do you reference a variable?

A

The variable name preceded by a dollar sign. For example if we had a variable called VARIABLE and we wanted to have that printed to the console, we could type the following: echo $VARIABLE

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

How do you set a variable?

A

The name of the variable followed by an equal sign followed by the value you want to assign the variable. You also need to export this variable using the export command. For example, if we wanted to create a variable called VARIABLE and set it to be a value of some_variable, we can achieve that by doing either of the following:

export VARIABLE=some_variable

OR

VARIABLE=some_variable
export VARIABLE

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

How do you delete an environment variable?

A

unset followed by the name of the variable (no dollar sign preceding the variable name in this case).

For example if we wanted to delete a variable called VARIABLE we can do so by typing the following:

unset VARIABLE

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

What is less?

A

less (similar to more) is a reading utility that basically lets you read information one page at a time while also allowing you to move both forward and backward.

To move forward a page, you press spacebar
To move backward you press v
To quit you press q

Linux mans (manuals) use the less reader but you can apply it to any readable file

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

What is the text based help system available on linux and how do you access it?

A

man, which is short for manual and you can apply it to even the man command itself. For example if you type, man man, you get the manual for the man command.

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

How many different sections can there be to a manual?

A

9

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

What are the different sections to a manual?

A
  1. Executable programs and shell commands
  2. System calls provided by the kernel
  3. Library calls provided by program libraries
  4. Device files (usually stored in /dev)
  5. File formats
  6. Games
  7. Miscellaneous (macro packages, conventions, and so on)
  8. System administration commands (programs run mostly or exclusively by root)
  9. Kernel routines
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If you’re only interested in one section of the manual for a given program, how do you access that?

A

man number_section_of_interest command

For example, if I was concerned only with the games section of the man for less, I would type the following:

man 6 less

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

Some programs have moved to an alternative to man pages. What are these called and what makes them different?

A

These are called info pages and they utilize hypertext format so that you can move more quickly between different sections of the documentation.

You call the info command the same way you’d call the man command

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

What are the three most important types of streams?

A

Standard input (stdin), standard output (stdout), and standard error (stderr)

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

How do you redirect streams?

A

> This redirects the stdout stream to a given file… if the file doesn’t exist, it’s created, if the file does exist, it’s overwritten

> > This redirects the stdout stream to a given file and appends that data to the file’s existing contents. If the file doesn’t exist, it’s created

2> Creates a new file for stderr info or overwrites an existing file with that info

2» Appends stderr to an existing file, if the file doesn’t exist it’s created

&> Creates a new file containing both stdout and stderr, if the file exits it’s overwritten

< Sends the contents of a file to be used as stdin

&laquo_space;Accepts text on the following lines as stdin

Unlike most redirection operators, the text immediately following the &laquo_space;code isn’t a fi lename; instead, it’s a word that’s used to mark the end of input. For instance, typing someprog &laquo_space;EOF causes someprog to accept input
until it sees a line that contains only the string EOF (without even a space following it).

<> Causes the specified file to be used for both standard input and standard output

tee causes a specified file to capture stdout but also display that stdout immediately, by default this will overwrite files; however, if you want this to append to an existing file, you’ll need to apply the -a flag to it.

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

What can you do if you want to get rid of data or, for example, a program is generating too many error messages?

A

Redirect standard output and/or standard error to /dev/null

Say the program the that was being too noisy was called some_program and we wanted to achieve the task mentioned in the question, we could type the following:

some_program 2> /dev/null

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

xargs

A

Command that builds a command from its standard input. The basic syntax for this command is as follows:

xargs [options] [command [initial-arguments]]

Example command to delete all files that match a certain pattern:

find ./ -name “*~” | xargs rm

17
Q

How might you delete all files that match a certain pattern in the name? In this example, let’s say that means files that end in a tilda.

A

find ./ -name “*~” | xargs rm

rm find ./ -name “*~”

These backticks work because linux treats the code within them as a separate command

18
Q

How do you concat two files together?

A

You can use the cat command followed by the two files that you want to combine. Let’s say that in our pwd we have files one and two. If we want to apply cat to them we would type the following:

cat one two

This will only stream to the stdout so in order to get the output into a file we’ll want to redirect the stream to another file by typing the following:

cat one two > three

This will put the output in a file called three which will be created if it doesn’t exist or overwritten if it does.

19
Q

What are some options available for cat?

A

If we want to remove unnecessary lines we can use the -s which will compress to only contain a single blank line. We can number each line by using the -n option. We can also denote the ending of each line with a $ by using the -e option or we can use the -t option to show special characters. Nothing prevents us from using all of these from what I understand.

20
Q

How would you join two files similar to how you might join to database tables?

A

join filename1 filename2

The joined column will be combined into 1

This will stream to stdout, so if you want to save the output of the join function you’ll need to redirect to another file. So if you want to save, you might want to do something like the following:

join filename1 filename2 > filename3

Join makes a few assumptions.

  1. The columns are space delimited and that each row is on its own line
  2. Both files have the same ordering of lines
  3. You want to join on the first column of both files

You can modify the separator with the -t char option where char is the separator and you can tell join to ignore case when supplying the -i option. You can also modify which columns you’re joining on using the -1 col and -2 col flag where col is the column number of interest for each of the respective files.

21
Q

How do you simply merge two files together?

A

paste filename1 filename2

this will combine the two files line by line separated by tabs where contents of filename1 meet filename2