Linus Flashcards
What is a shell?
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.
What are the common shells?
- bash- Bourne-Again Shell
- sh- Bourne Shell
- ksh- Korn Shell
- csh- C Shell
- tcsh- TC Shell
Features ofbash
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
Features ofsh
sh- The Bourne shell - An earlier version of the Bash shell, and is similar in many ways. Sh is the original shell created by Steve Bourne
Features ofksh
ksh- The Korn shell - Developed by David Korn. Ksh has scripting features not found in bash.
Features ofcsh
cshThe C-shell - Uses syntax similar to syntax used in the C programming language.
Features oftcsh
tcsh- The TC shell - An improved version of csh. It offers command line editing and completion features not available with csh.
Common characteristics of all shells
◇ 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 do you get into the shell?
◇ Boot into it at run level 3 (no GUI)
◇ Access it through a terminal window using a terminal application within the GUI
What is the difference between how a Linux shell recognizes the path to executable programs compared to how a DOS environment recognizes the path?
◇ 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 can you execute commands that are not in thePATHenvironment variable?
◇ 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 can you execute commands in the current working directory?
Prefix the command with a “dot-slash” (./)
What types of items can Tab complete be used to complete once you start typing the entities’ name?
Files and directories.
What is tab-completion?
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 does command history work?
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.
What common commands are used to navigate through shells?
◇ ‘pwd’
◇ ‘ls’
◇ ‘cd’
Which file contains the history of shell commands?
~/.bash_history
What does the tilde symbol (~) in the command prompt represent?
The tilde symbol (~) in the prompt indicates the present working directory is the home directory of the current user.
What is the command path?
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 do you execute programs in the shell?
◇ 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.
Are filenames and paths case-sensitive?
Yes
How does tab-completion work?
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 do you recall the previous command and scroll through all previous commands?
Press the up arrow at the command prompt to print the last command. Press it again to scroll through all previous commands.
What does thepwdcommand do?
Shows the present working directory.
What does thewhoamicommand do?
Displays the current username.
What does theunamecommand do?
unameprints system information.
What does the commanduname -ado?
uname -aprints all system information.
What does the commanduname -odo?
uname -oprints all system information.
What does the commanduname -pdo?
uname -pprints all system information.
What does thesucommand do?
suswitches users. With no arguments, switches to the root user.
What does the commandsu -l user_namedo?
su -l user_nameswitches to the specified user in a login shell.
What does the commandsu user_namedo?
su user_name(without the dash, but with the username) switches to the user.
What does the commandsu - user_namedo?
su - user_name(with the dash and username) switches to the user and loads the user’s environmental variables.
What does the commandsu -do?
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.
What are the different shell prompt symbols and what do they represent?
◇ ‘#’ indicates the current user is the root user.
◇ ‘$’ indicates the current user is a normal user.
What does theexitcommand do?
Exits the login shell or exits back to the original user after using the su command.
What does theexeccommand do?
Runs an executable and replaces the shell with the new process created by the executable file.
What does thecdcommand do?
Changes directories.
What does thelscommand do?
Shows names of files and directories in the current directory.
What are some commonlsoptions and what do they do?
◇ ls -ashows all files and directories, including hidden files.
◇ ls -lshows information about files including size, permissions, owner, and modified date.
◇ ls -ddisplays only directories.
◇ ls -ssorts files by size.
◇ ls -Xsorts by extension.
What does a blue file color represents?
Blue: directories
What does thehistorycommand do and what does the-coption do?
Shows all commands in the current user’s history queue. The -c option clears the history list.
What does a white file color represents?
White: text files
What does a cyan file color represents?
Cyan: symbolic links
What does a magenta file color represents?
Magenra: image file
What does a red file color represents?
Compressed file
What does theclearcommand do?
Clears the shell screen.
What does thechshcommand do and what do the options-sand-ldo?
chshchanges the default shell.◇ chsh -schanges to a different installed shell. The command prompts for a password.
◇ chsh -llists all installed shells.
What is aloginshell used?
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 (likebash).
What is anon-loginshell?
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.
What is the effect of a leading period (.) before a filename?
The file is hidden and is not displayed by the ‘ls’ command unless the ‘-a’ switch is used.
Which shell configuration files are executed by non-login shells?
Only.bashrc
Which shell configuration files are used by RedHat, CentOS, and Fedora Linux (in addition to/etc/profile)?
◇ ~/.bashrc
◇ ~/.bash_profile
◇ ~/.bash_logout
Which shell configuration files are used by SUSE Linux (in addition to/etc/profile)?
◇ ~/.bashrc
◇ ~/.profile
How do you list hidden files in addition to regular files?
ls -a
How do some distributions run the~/.bashrcshell configuration file in login shells?
By calling (sourcing) the script from within the.bash_profilescript.
How do you append a path onto the end of the currentPATHvariable?
PATH=$PATH:new_path
What are shell configuration files?
Scripts that execute when a shell starts.
What determines which shell configuration files are executed?
The shell type.
What are the two different types of shells?
◇ 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.
How is~/.bashrcused?
Shell configuration file. Stores shell preferences for individual users. Executed by non-login shells (and by login shells for some distributions).
How is/etc/profileused?
Shell configuration file. Stores system-wide configuration commands and is used primarily to set environment variables. Executed by login shells.
How is~/.bash_profileused?
Shell configuration file. Stores shell preferences for individual users. Executed by login shells.
How is~/.bash_loginused?
Shell configuration file. Stores commands that execute when a user logs in. Executed by login shells. (Not executed if~/.bash_profileexists.)
How is~/.profileused?
Shell configuration file. Stores configuration preferences similar to /etc/profile, but for individual users. Executed by login shells. (Not executed if~/.bash_profileor~/.bash_loginexist.)
How is~/.bash_logoutused?
Shell configuration file. Stores commands that execute when a user logs out. Executed by login shells. Executed by login shells.
Which shell configuration files are executed by login shells and in what order?
- /etc/profile
- ~/.bash_profile(If this file is found, the shell does not look for additional configuration script files)
- ~/.bash_login(If this file is found, the shell does not look for additional configuration script files)
- ~/.profile(This file only executes in the absence of the preceding two)
- ~/.bashrc(Depending on the distribution)