1.1 The Shell Flashcards

2
Q

What is a shell?

A

The Command Line Interface (CLI) or Text User Interface (TUI) that administrators use to control a Linux operating system. Users and programs use the shell to send commands to the system. A shell might be opened inside a Graphical User Interface (GUI), or might be the sole method used to run the computer.

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

What are the common shells?

A
  • bash - Bourne-Again Shell
  • sh - Bourne Shell
  • ksh - Korn Shell
  • csh - C Shell
  • tcsh - TC Shell
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Features of bash

A
  • *bash** - The Bourne-again shell - The standard shell used in most Linux computers. It uses commands similar to a UNIX shell. Bash includes features such as:
  • Command completion when pressing the tab key
  • Command history
  • Improved arithmetic functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Features of ksh

A

ksh - The Korn shell - Developed by David Korn. Ksh has scripting features not found in bash.

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

Common characteristics of all shells

A
  • A Linux system can use multiple shells at the same time.
  • A list of shells is stored in the /etc/shells file.
  • All shells are interfaces with the kernel, separate and distinct from it.
  • Shells are run both interactively by end users and automatically by the computer’s processes.
  • Shells can run within one another either interactively when a user starts a second shell from the first shell’s command line, or automatically by scripts or programs.
  • Shells use configuration files to establish their operating environments.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you get into the shell?

A
  • Boot into it at run level 3 (no GUI)
  • Access it through a terminal window using a terminal application within the GUI
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between how a Linux shell recognizes the path to executable programs compared to how a DOS environment recognizes the path?

A
  • In DOS or Windows, the shell searches for your command in the current directory first, followed by the directories in the PATH variable.
  • In Linux, the shell only searches the directories in the PATH variable for your command. It does not search the current directory.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can you execute commands that are not in the PATH environment variable?

A
  • Use an absolute path
  • Use a relative path
  • Copy or move the command file to a directory that is in the path (like ~/bin or /bin)
  • Add the directory that contains the command file to the PATH variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can you execute commands in the current working directory?

A

Prefix the command with a “dot-slash” (./)

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

What types of items can Tab complete be used to complete once you start typing the entities’ name?

A

Files and directories.

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

What is tab-completion?

A

A shell feature that gives you the ability to type part of a filename and then have the shell complete the filename (or provide a list of matching suggestions) by hitting the tab key.

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

How does command history work?

A

Every time you enter a command, that command is written to a hidden file in your home directory. You can access previous commands with the up- and down-arrow keys.

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

What common commands are used to navigate through shells?

A
  • ‘pwd’
  • ‘ls’
  • ‘cd’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which file contains the history of shell commands?

A

~/.bash_history

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

What does the tilde symbol (~) in the command prompt represent?

A

The tilde symbol (~) in the prompt indicates the present working directory is the home directory of the current user.

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

What is the command path?

A

The set of directories in which Linux searches to find executable files for the commands typed into the shell prompt:

  • The path does not include the present working directory.
  • To see the path, type echo $PATH.
  • To add a directory to a path, type PATH=$PATH:.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How do you execute programs in the shell?

A
  • Type the executable name in the present working directory if the program is in the command path.
  • Type ./filename to run an executable in the present working directory. (./ indicates the present working directory.)
  • Type the full pathname to the file to run an executable from anywhere.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Are filenames and paths case-sensitive?

A

Yes

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

How does tab-completion work?

A

Type the beginning of the name, then press Tab to complete a file, command, or directory name. (Press Tab twice if there is more than one possible file, command, or directory name.)

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

How do you recall the previous command and scroll through all previous commands?

A

Press the up arrow at the command prompt to print the last command. Press it again to scroll through all previous commands.

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

What does the pwd command do?

A

Shows the present working directory.

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

What does the whoami command do?

A

Displays the current username.

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

What does the uname command do?

A

uname prints system information.

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

What does the command uname -a do?

A

uname -a prints all system information.

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

What does the command uname -o do?

A

uname -o prints all system information.

27
Q

What does the command uname -p do?

A

uname -p prints all system information.

28
Q

What does the su command do?

A

su switches users. With no arguments, switches to the root user.

29
Q

What does the command su -l user_name do?

A

su -l user_name switches to the specified user in a login shell.

30
Q

What does the command su user_name do?

A

su user_name (without the dash, but with the username) switches to the user.

31
Q

What does the command su - user_name do?

A

su - user_name (with the dash and username) switches to the user and loads the user’s environmental variables.

32
Q

What does the command su - do?

A

su - (with the dash, but no username) switches to the root user and loads the root user’s environmental variables. The root user account is the Linux system superuser. It can perform any task; some utilities do not work if the administrator is not logged in as the root user.

33
Q

What are the different shell prompt symbols and what do they represent?

A
  • ’#’ indicates the current user is the root user.
  • ’$’ indicates the current user is a normal user.
34
Q

What does the exit command do?

A

Exits the login shell or exits back to the original user after using the su command.

35
Q

What does the exec command do?

A

Runs an executable and replaces the shell with the new process created by the executable file.

36
Q

What does the cd command do?

A

Changes directories.

37
Q

What does the ls command do?

A

Shows names of files and directories in the current directory.

38
Q

What are some common ls options and what do they do?

A
  • ls -a shows all files and directories, including hidden files.
  • ls -l shows information about files including size, permissions, owner, and modified date.
  • ls -d displays only directories.
  • ls -s sorts files by size.
  • ls -X sorts by extension.
39
Q

What are some common ls file colors and what do they represent?

A
  • Blue: directories
  • White: text files
  • Cyan: symbolic links
  • Magenta: image files
  • Red: compressed files
40
Q

What does the history command do and what does the -c option do?

A

Shows all commands in the current user’s history queue. The -c option clears the history list.

41
Q

What does the clear command do?

A

Clears the shell screen.

42
Q

What does the chsh command do and what do the options -s and -l do?

A
  • *chsh** changes the default shell.
  • chsh -s changes to a different installed shell. The command prompts for a password.
  • chsh -l lists all installed shells.
43
Q

What is a login shell used?

A

A shell that is started when a user first logs onto a system - such as when your system is configured to boot directly into a shell environment (like bash).

44
Q

What is a non-login shell?

A

A shell that is started from within a running system by a user who has already logged onto that system - such as when you start a terminal program from within a GUI.

45
Q

What is the effect of a leading period (.) before a filename?

A

The file is hidden and is not displayed by the ‘ls’ command unless the ‘-a’ switch is used.

46
Q

Which shell configuration files are executed by non-login shells?

A

Only .bashrc

47
Q

Which shell configuration files are used by RedHat, CentOS, and Fedora Linux (in addition to /etc/profile)?

A
  • ~/.bashrc
  • ~/.bash_profile
  • ~/.bash_logout
48
Q

Which shell configuration files are used by SUSE Linux (in addition to /etc/profile)?

A
  • ~/.bashrc
  • ~/.profile
49
Q

How do you list hidden files in addition to regular files?

A

ls -a

50
Q

How do some distributions run the ~/.bashrc shell configuration file in login shells?

A

By calling (sourcing) the script from within the .bash_profile script.

51
Q

How do you append a path onto the end of the current PATH variable?

A

PATH=$PATH:new_path

52
Q

What are shell configuration files?

A

Scripts that execute when a shell starts.

53
Q

What determines which shell configuration files are executed?

A

The shell type.

54
Q

What are the two different types of shells?

A
  • Login shells - run when the system starts and is only using the Text User Interface (TUI) as the user interface.
  • Non-login shells - run when the system boots into a Graphical User Interface (GUI) and a user starts a terminal session.
55
Q

How is ~/.bashrc used?

A

Shell configuration file. Stores shell preferences for individual users. Executed by non-login shells (and by login shells for some distributions).

56
Q

How is /etc/profile used?

A

Shell configuration file. Stores system-wide configuration commands and is used primarily to set environment variables. Executed by login shells.

57
Q

How is ~/.bash_profile used?

A

Shell configuration file. Stores shell preferences for individual users. Executed by login shells.

58
Q

How is ~/.bash_login used?

A

Shell configuration file. Stores commands that execute when a user logs in. Executed by login shells. (Not executed if ~/.bash_profile exists.)

59
Q

How is ~/.profile used?

A

Shell configuration file. Stores configuration preferences similar to /etc/profile, but for individual users. Executed by login shells. (Not executed if ~/.bash_profile or ~/.bash_login exist.)

60
Q

How is ~/.bash_logout used?

A

Shell configuration file. Stores commands that execute when a user logs out. Executed by login shells. Executed by login shells.

61
Q

Which shell configuration files are executed by login shells and in what order?

A
  1. /etc/profile
  2. ~/.bash_profile (If this file is found, the shell does not look for additional configuration script files)
  3. ~/.bash_login (If this file is found, the shell does not look for additional configuration script files)
  4. ~/.profile (This file only executes in the absence of the preceding two)
  5. ~/.bashrc (Depending on the distribution)
62
Q

Which command switches to a user using a login shell?

A

su -l