Linux basics session 3

Course overview

Desktop

middle click on mouse - paste highlighted text (extra copy paste function along with traditional CTRL+C and CTRL+V inspect element in FireFox when right-clicking on an element of the page (getting URL of a picture)

Command Line Interface (CLI)

quick access to a terminal window CTRL+ALT+T

arrow up - recall last command(s) and modify it - along with TAB used most of the time CTRL+R - reverse lookup in last commands - search by a given string (type something) - extra CTRL+R jumps to the next match; CTRL+SHIFT+R jmups to the previous match terminal session can be closed by typing exit or pressing CTRL+D

CTRL+C is used for breaking currently running program / clearing current line for copy&paste in terminal we need to use old fashioned CTRL+Insert (copy), SHIFT+Insert (paste) this is the same clipboard as CTRL+C on non-shell windows (e.g. browser), the same as rght-click and Copy.

previous session's self-study: use mkdir -p to create parent dirs navigate in directory structure using cd <dir> and cd .. tree to display directory content graphically - this is not installed by default sudo apt install tree - install tool tree using ubuntu package manager - sudo at the beginning is to run command as root (admin) - will prompt for your password - this is how software is usually installed on linux

cat data.txt - print out complete text file content more data.txt - display text file content paginated - limited options less data.txt - display text file content paginated - using HOME. END, PGUP, PGDOWN to browse the file; searching for a content using / followed by a pattern to search for - browsing results using N (next) and P (previous); quit anytime pressing Q

Files can be of two types: - text files (can be printed in terminal, can be edited with an editor) - binary files (cannot be printed in terminal, requires special tool/program) file obr01.jpg examining file type by "magic number" - good when not sure about file type and appropriate tool/program to use

Editors

vi - old editor available on all environments - cumbersome to control - two modes SELECT and INSERT, how to exit: press ESC to be in select mode, press : to get command prompt on the bottom, write q! to exit without saving the changes, press wq to save changes before exiting

vim - slightly better user experience, exit sequence is the same as vi

nano - decent text editor with intuitive and predictable controls - save with CTRL+S, exit with CTRL+X

grep command

grep <options> <pattern> <file> - find a text (pattern) in a file, works on a line by line basis

grep computer /usr/share/dict/words - shows matching lines

grep -n ... - display line numbers

grep -c ... - count of matching lines

grep ^computer$ ... - regular expressions matching - exact match of the whole line

Input/Output Streams

every command gets STDIN and yields STDOUT, command can be chained using | (pipe)

grep computer /usr/share/dict/words | wc -l - this passes result of grep command to the wc command - that will output number of lines

Self-study

Is there any difference between above command and using -c grep option?