# LPI Linux Certification/Work On The Command Line
## Detailed Objective

(LPIC-1 Version 5.0)
Weight: 4
Description:
Candidates should be able to interact with shells and commands using the command line. The objective assumes the Bash shell.
Key Knowledge Areas:
* Use single shell commands and one line command sequences to perform basic tasks on the command line.
* Use and modify the shell environment including defining, referencing and exporting environment variables.
* Use and edit command history.
* Invoke commands inside and outside the defined path.
The following is a partial list of the used files, terms and utilities:
* bash
* echo
* env
* export
* pwd
* set
* unset
* type
* which
* man
* uname
* history
* .bash_history
* Quoting

## Command line

Command lines have a common form:
Examples:
Command lines can be stored into a file for a script.
To display a string to the standard output (stdout) use echo.

## Shells and Bash

The order of precedence of the various sources of command when you type a command to the shell are:
* Aliases
* Keywords, such as if, for and more.
* Functions
* Built-ins like cd, type, and kill.
* Scripts and executable programs, for which the shell searches in the directories listed in the PATH environment variable.
If you need to know the exact source of a command, do:
Not the same as:
To list all the built-in commands use help.
/bin/bash can be invoked at login time or explicitly from the command line. At login time the following script files will be executed:
* /etc/profile default system file
* $HOME/.profile if it exists
* $HOME/.bash_profile if it exists
When bash is executed the following script files will be executed
* /etc/bash.bashrc if it exists
* $HOME/.bashrc if it exists
When a user explicitly invokes a bash shell, the following script files will be executed:
* /etc/bash.bashrc if it exists
* $HOME/.bashrc if it exists
The history of commands typed from the bash shell are stored in ~/.bash_history. A script is a list of commands and operations saved in a text file to be executed in the context of the shell. The bash scripts intend to setup your environment variables and more.
Overlay /bin/bash
Each time you execute a program a new process is created. When the program terminates, the process will be terminated and you get back your prompt. In some cases you can run a program in background with the '&' following the command.
In some situations, it is also possible to overlay the running process bash. exec [program] This is usefull when you don't need to get the prompt back. The login program for example can be a good example to overlay the bash process in which it has been started.

## Shell variables

All local variables to the bash session can be viewed with set.
To declare a local variable, do:
To unset a variable, do:
All the environment variables can be viewed with env. To declare a variable that will be seen by other shells use export.
or
The variable will only be seen by the shell that has been started from where the variable has been declared. Here are some important variables:
* HOME: Home directory of username logged in.
* PATH: Command search path.

## Man pages

The online manuals describe most of the commands available in your system.
If you are looking for a key word in all the man pages, use the -k option.
The location of all the man pages must be set in the MANPATH variable.

## Exercises

* Get information on the useradd and userdel commands.
* Create two new accounts user1 and user2 and set the passwords to those accounts with the passwd command. As root lock the accounts and check if you can still log in.
* What is the command to concatenate files?
* Declare and initialize the following environment variables: NAME and LASTNAME. Use echo to print them out.
* Start a new bash (type bash) and check that you can still see those declared variables.
* Use exec to start a new bash session. Can you still see those declared variables?
* Use date to display the month.
* Add a new user named notroot with root's rights and lock the root account.
* Exercises results