2.1 Command Line Basics Flashcards

1
Q

What are the two types of commands. Explain the differences.

A
  1. Internal - part of the shell itself and are not separate programs. Their purpose is executing tasks inside the shell (e.g. cd, set, export).
  2. External - These commands reside in individual files. These files are usually binary programs or scripts. When a command which is not a shell builtin is run, the shell uses the PATH variable to search for an executable file with same name as the command.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe three types of quotes in Bash.

A
  1. Double quotes: double quotes tell the shell to take the text in between the quote marks (“…”) as regular characters. All special characters lose their meaning, except the $ (dollar sign), \ (backslash) and ` (backquote).
  2. Single quotes: single quotes don’t have the exceptions of the double quotes.
  3. Escape characters: remove special meanings of characters from Bash.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to see if a command is internal or external?

A

Use command “type” and the command.

$ type echo
echo is a shell builtin
$ type man
man is /usr/bin/man

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

What is a variable? What does it do?

A

Variables are pieces of storage for data, such as text or numbers. Once set, a variable’s value can be accessed at a later time.

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

What are the two types of variables? Describe them.

A
  1. Local variables: are available to the current shell process only. If you create a local variable and then start another program from this shell, the variable is not accessible to that program anymore. Use the “=” to indicate local. ($ greeting=hello). Use “$” to access the variable. $ echo $greeting
  2. Environment variables: available both in a specific shell session and in sub processes spawned from that shell session. Can be used to pass configuration data to commands which are run. The majority of the environment variables are in capital letters (e.g. PATH, DATE, USER). A set of default environment variables provide, for example, information about the user’s home directory or terminal type. Sometimes the complete set of all environment variables is referred to as “the environment”.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the command “echo” do? How is it used?

A

Displays any variable. In order to access the value of the variable you will need to use $ (dollar sign) in front of the variable’s name.

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

How to remove a variable?

A

Use command “unset”.

$ echo $greeting
hey
$ unset greeting
$ echo $greeting

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

What does the PATH variable do?

A

It stores a list of directories, separated by a colon, that contain executable programs eligible as commands from the Linux shell.

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

What does the command “which” do?

A

It stores a list of directories, separated by a colon, that contain executable programs eligible as commands from the Linux shell.

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

What do the characters below do?

  1. $ (dollar sign)
  2. \ (backslash)
  3. ’ ‘ (single quotes)
  4. ” “ (double quotes)
A
  1. $ must be used to reference a variable.
  2. \ is the Bash escape character to preserver the literal value of the next following character (except for newline)
  3. ’ ‘ preserve the literal value of every character, including escape character.
  4. ” “ preserve literal value of most characters within quotes except for $, ‘ ‘, and .
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the command “w” do?

A

Shows who is logged on on and what they are doing.

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

What does the command “last” do?

A

Shows listing of last logged in users. It searches through the /var/log/wtmp file (or the file designated by the -f option) and displays a list of all users logged in (and out) since that file was created.

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