Linux Professional Institute Exam 101 / LPIC 101

Chapter 1

Video 10: Section 103.1 - Work on the command line

- A . <dot> before files or folders in the file name will hide them
- Display hidden files
    - #ls -a
-  Displays the environment variables
    - #env
    - Under path are the directorys that linux searches for programs in
- Set a environment variable:
    - #export ABC=123
    - #set
    - ABC is the variable name
    - 123 is the variable value
- Display a variable using #echo $ABC
- Remove a environment variable:
    - #unset ABC
- Display the command history
    - #history
- Redo commands using [up]
- Complete commands/display command options using [TAB]
- Display information about the system that you are on
    - #uname -a
- Lookup a command
    - #man {command}
- Look for keywords in man
    - #man -k {search word}
- Start a new shell
    - #bash
- Start a command in basic settings and exit when the command is done
    - #exec {command}

Video 11: Secton 103.2 - Process text streams using filters

- Glue multiple files together
    - #cat {options} FILE1.txt FILE2.txt > EXPORT.txt
- Remove sections from each line of files
    - #cut {options} FILE.txt
- Convert tabs into spaces
    - #expand {options} FILE.txt
- Format text
    - # fmt {options} FILE.txt
        -[ -w 5 ]= every line is maximum 5 characters wide
- Outputs first 10 lines of a file
    - # head {options} FILE.txt
        -[ -n 2 ]= display only the fist 2 lines
- Dumps file in octal
    - # od {options} FILE.txt
        -[ -c ]= display characters
- Merge lines on a common field
    - # join {options} FILE1.txt FILE2.txt (leaves out common field)
- Number lines in a file
    - # nl {options} FILE.txt
- Merge lines in a file
    - # paste {options} FILE1.txt FILE2.TXT
- Prepare a file for printing (each file gets its own page)
    - # pr {options} FILE1.txt FILE2.txt
- Replace words/characters by others
    - # sed {options} FILE.txt
        -[ -e 's/pants/dresses/' ] = Replace 'pants' by 'dresses'
- Sort lines in a file (standard it sorts icons by alphabeth)
    - # sort {options} FILE.txt
        -[ -r ] = sorts it backwards
        -[ -R ] = sorts it random
- Split a file into pieces
    - # split {options} FILE.txt
        -[ -l 2] = split into files, with 2 lines per file
        -[ -b 5] = split into files, with 5 bytes per file
- Outputs last 10 lines of a file
    - # tail {options} FILE.txt
        -[ -f ] = keeps loading the last 10 lines (tail watches it)
- Traslate characters to other characters
    - # tr {options} SET1 SET2
        -[ -t ] = Translate the characters in SET1 into characters from SET2
        -[ -d ] = Deletes all characters in SET1
        -[ -s ] = Remove reoccurring letters hello = helo
- Convert spaces into tabs (standard it only does the beginning blanks)
    - # unexpand {options} FILE.txt
        -[ -a ] = convert all the spaces
- Will only display one of the lines if there are duplicates
    - # uniq {options} FILE.txt
        -[ -c ] = Displays the number of occurrences of the same line
        -[ -d ] = Display only the lines that have repeated lines
        -[ -u ] = Display only the lines that are unique
- Counts the number of lines, words and bytes
    - # wc {options} FILE.txt
        -[ -w ] = Display only the word count
        - You can replace FILE.txt with * to display the statistics of all the files in the folder
        - Shows [number of lines], [number of words], [number of bytes], [filename]

Video 13: Section 103.4 - Use streams, pipes, and redirects

- STDin
    - Stuff a program chews up
- STDout
    - Stuff a program spits out
- STDerr
    - Where a program complains
- Creates/Overwrites a file containing STDOUT
    - >
- Adds STDOUT to a existing file (one will be created if not exists)
    - >>
- Creates/Overwrites a file containing STDERR
    - 2>
- Adds STDERR to a existing file (one will be created if not exists)
    - 2>>
- Creates/Overwrites a file containing STDOUT + STDERR
    - &>
- Sends content of a file as STDIN
    - <
- Sends next lines as STDIN, argument specifies end of file input
    - <<
- Uses a file as STDIN + STDOUT
    - <>
- Uses STDOUT from x as STDIN from y (can be used to infinity)
    - x | y
- Displays/sends (overwrites) the STDOUT to as many files as specified
    - | tee
- Displays/adds the STDOUT to as many files as specified
    - | tee -a
- Makes arguments from STDin for the command specified
    - # ls | xargs echo
        - A list of files is being uses as argument for echo

Video 16: Section 103.7 - Search text files using regular expressions

- Regular Expressions (.. is the searchterm)
    - ^.. = beginning with ..
    - ..$ = ending with ..
    - (dot).. = need to have a character before ..
    - x | y = x OR y
- Search for characters/words using SOME REGULAR EXPRESSIONS
    - # grep {options} {searchterm) FILE.txt
        -[ -n ] Print the numbers of the lines
        -[ -i ] The search is performed case insensitive
        -{searchterm} Where you are looking for
- Search for characters/words using EXTENDED REGULAR EXPRESSIONS
    - # egrep {options} {searchterm} FILE.txt
        -{searchterm} = '^(b|d)oo'
            - All lines that start with a b, d and have oo directly after
        -{searchterm} = '^[a-k]'
            - All lines that start with a t/m k (lowercase)
        -{searchterm} = '^[a-k]|[A-K]'
            - All lines that start with a t/m k (lowercase) OR A t/m K (uppercase)
- Search for characters/words using LITERAL STRINGS
    - # fgrep {options} {searchterm} FILE.txt
        -{searchterm} = fa$
            - All lines that start with fa
- Edit streams with regular expressions
    - # sed {options} {action} FILE.txt
        - [ -e ] = edit a file
        - [ -re ] = r means using regular expressions / e means edit a file
        - {action} = 's/oo/00'
            - Substitute (replace) all oo with 00
        - {action} = 's/^(B|b)/C/'
            - Substitute (replace) all letters from words that begin with a B or b, with a capital C