JUNIOR

ACADEMY

8/6/2016

homework

review!

gnu/linux

  • What is GNU/Linux?
    • Unix-like OS composed of GNU packages/coreutils and the Linux kernel
  • What is GNU?
    • Free and open source software (FOSS) containing the core utilities and basic tools
  • What is Linux?
    • Kernel
      • Central core of OS
      • Handles Input/Output requests from software
      • Links software and hardware (CPU)

why use it?

  • Privacy
  • Free
    • Not just free as in money, but freedom
  • Open and shared
  • More control
    • More direct access to your computer
    • Get to do more cool things
    • You know what you're doing and what's happening
    • No viruses!
  • Abundance of different distributions

distros

  • Community/company-created OSes using the Linux kernel and a package management system
  • When people say they use Linux, they're using a distribution of it
  • Differences
    • Package Manager
    • Desktop Environment
    • Default configurations
    • Default packages (software/programs)
    • Release schedule
      • Stable
      • Rolling
    • Logo

package manager

  • What is a Package Manager?
    • Collection of software tools that automates installing, configuring, upgrading, and removing packages
    • You don't have to manually install everything
  • Each distro has its own package manager
    • Debian-based: apt
    • Arch-based: pacman
    • Red Hat-based: dnf
    • Gentoo-based: portage
  • Repositories are servers that contain sets of packages
  • sudo apt install sl && sudo apt install cowsay

sudo

  • superuser do
  • Grants root access for the given command
    • Allows you to configure the files in the root directory (excluding /home)
  • Use it when you get the error "permission denied"
  • use it ONLY if you know what you're doing
  • su
    • su -c == equivalent to sudo
    • su -l == login as given user (root if no argument is passed)

unix files

directories

  • Everything is a file or directory; don't need extensions
  • / - the root directory, beginning of everything
  • /bin - contains binaries (programs) that allow the system to boot and run
  • /boot - contains the Linux kernel, initial RAM disk image (to boot), and the boot loader
  • /dev - contains device nodes (devices such as USBs, etc)
  • /etc - contains system-wide config files & shell scripts that start the system at boot time
  • /home - contains user directories
  • /lib - contains library files used by core system programs (comparable to Windows' DLLs)

directories

  • /lost+found - used in the case of a partial recovery from a filesystem corruption
  • /media - contains mount points for removable media tat are automatically mounted (newer systems)
  • /mnt - same as /media except for manually mounted media (older systems)
  • /opt - used to install optional software (usually commercial)
  • /proc - virtual filesystem that tells you how to kernel sees/interacts with your computer
  • /root - home directory for root account
  • /sbin - contains system binaries for vital system tasks
  • /tmp - contains temporary files created by programs
  • /usr - contains programs and support files used by regular users (not root)

directories

  • /usr/bin - contains executable programs
  • /usr/lib - contains shared libraries for /usr/bin programs
  • /usr/local - contains programs not included with the distro, but are intended for system-wide use (usually programs compiled from source code)
  • /usr/sbin - contains more system administration programs
  • /usr/share - contains the shared data used by programs like config files, icons, supplementary files, etc. (Comparable to Windows Program Files)
  • /usr/share/doc - contains documentation for packages
  • /var - contains data that is likely to change (Ex. databases, spool files, user mail, etc)
  • /var/log - contains log files, records of system activity

ubuntu

  • In this class, our main OS will be Ubuntu
  • Based on Debian
  • Beginner-friendly
  • Uses Unity as the default DE
  • uses .deb files as its packages
    • use the dpkg command to manually install packages downloaded from the internet
    • Ex. dpkg -i chromium-widevine.deb
  • Try to use the terminal as much as possible, refrain from using the Ubuntu Software applications

command line interface

  • Also known as the terminal
  • Gives you complete access/control over your machine
  • Use wisely!
    • You don't want to break your system
    • NEVER type in commands if you don't know what they do

apt

  • Advanced Package Tool
  • apt is the package manager that comes with Debian-based distros
  • If you'd like, you can use aptitude, which is like apt, except interactive
    • If you opt to do this, ONLY use apt or aptitude, don't switch between the two or something will break
    • Also, when performing dist-upgrade, do it through apt, not aptitude
  • /etc/apt/sources.list determines your sources (repositories)

essential apt commands

  • apt search [argument] - searches the apt repo
  • apt install [argument] - installs the given package name
  • apt remove [argument] - removes the installed package
  • apt purge [argument] - completely removes an installed package and its configuration files
  • apt autoclean - removes .deb files for uninstalled packages
  • apt clean - removes all packages from the package cache
  • apt autoremove - removes dependency packages that are no longer needed
  • apt update - makes your source list up-to-date
  • apt upgrade - upgrades all installed packages 
  • apt dist-upgrade - same as above, except uses "smart" conflict resolution

installation time!

  • Use what you've learned about apt to install the following software:
    • Chromium
    • Vim
    • Docker
    • Geany
  • Remember the rules
    • Only install approved software
    • If there is something you'd like to install, ASK US FIRST
  • sudo apt update && sudo apt dist-upgrade

bash syntax

  • command -option [argument]
    • The command is the command that Bash executes
      • Ex. cd, touch, mkdir, ls
    • The option is written after a dash (-), it allows you to undergo different ways of executing the command
      • Ex. ls -a     The a option lists all of the files, including hidden ones
      • You can use multiple options at once, a la: pacman -Syu
    • The argument is whatever you're passing into the command
      • Ex. cd Desktop, passes in the Desktop argument to be cd'd into
  • Use spaces to separate commands, options, and arguments

more bash

  • Wildcards
    • * == any characters
    • ? == any single character
    • [characters] == any character that is a member of the set characters (Ex. :digit:, :lower:, :upper:)
    • Ex. b*.txt == any file beginning with 'b' followed by any characters and ending with '.txt'
  • All commands have a standard input (stdin), standard output (stdout), and standard error (stderr)

redirection

  • Redirecting standard output
    • command > file
      • ​overwrites/creates the file containing the output of the command
    • command >> file
      • appends the output to the end of the file's contents
  • Redirecting standard error
    • command 2> file
      • adding the descriptor '2' makes it redirect an error
      • &> redirects both stdout and stderr
  • Dispose of unwanted output by redirecting to /dev/null

redirection

  • Redirecting standard input
    • the cat command not only prints the contents of a file, it allows you to concatenate multiple files by using them as arguments
    • if you just type cat alone, you can type something in and that makes it an output until you press Ctrl+D
      • cat > lazy_dog.txt then type something in
      • command < file
        • changes the standard input from keyboard to file

pipelines

  • Pipe operator | (vertical bar) pipes the standard output of one command into the standard input of another
  • command1 | command2
  • Commands used on the pipeline to change the input before outputting it are called filters
    • sort combines multiple outputs into a single, sorted one
      • ls /bin /usr/bin | sort | less
    • uniq omits/reports repeated lines
      • ls /bin /usr/bin | sort | uniq | less
      • ls /bin /usr/bin | sort | uniq -d | less
    • wc prints the number of lines, words, and bytes
    • grep searches a file and prints lines matching a pattern
      • grep "full name" thisIsAFile.py
      • ls /bin /usr/bin | grep zip

exercise

In the terminal, navigate to the exercise1 directory in your Documents/exercises directory

 

Create an HTML_Files directory

In ONE command, move all of the html files into the HTML_Files directory.

Then, grep through the binDirectoryContents file to find all unique words containing "lib"

Use the | operator to search through the /usr/share/ directory for all files that end in a file extension.

python

  • What is Python?
  • Why are we using Python?

data types

  • String
    • "This is a string."
  • Boolean
    • True/False
  • Integer
    • whole numbers
  • Float
    • floating points
  • In Python, variables don't need to be typecasted

hello world!

  • cd into Documents and make a directory named "python_work", cd into that
  • Make a file called "hello_world.py"
  • Edit the file and type:
    • print("Hello world!")
  • Launch your new program in the terminal!
    • python3 file.py

operators

  • +, -, *, /, %, <, >
  • Open up your Python interpreter and try it out
    • Ex. Type "python3" into your terminal
    • >>> 5+5*10
  • Note: Ctrl+D quits out of the interpreter back into the terminal emulator!

variables

  • In the interpreter type in:
    • >>> fred = 100
    • >>> print(fred)
  • We just created a variable, called "fred"
  • What is the data type of the variable fred?
  • A variable is just something that stores value
  • A variable varies, and can be reassigned. Try:
    • >>> fred = 200
    • >>> john = fred
    • >>> print(john)

variables

  • Variables must follow certain naming conventions
    • NEVER start with a number
    • NO spaces
      • Use underscores or camel casing
    • No special characters (*,.!@#;: etc)
  • Syntax:
    • variableName = value
  • = vs ==
    • = is assignment
    • == checks equivalency
      • num = 5
      • num == 6

strings

  • Anything encased in quotes ("") is a string
  • In Python, you just need to put quotes around the value
    • >>> fred = "This is a string"
    • >>> print(fred)
  • You can use single quotes
    • Be consistent
    • Use double quotes if there is an apostrophe in the string
  • You can concatenate things to a string with +.
    • >>> str = "world!"
    • >>> print("Hello " + str)

tricks with strings

  • >>> print(20 * 'abcd')
  • A "%" can be a placeholder for values:
    • >>> mytext = 'I am %s years old'
    • >>> print(mytext % 12)
  • %s is used in the string, % to assign the value
  • Other ways of using it
    • >>> name1 = 'Joe'
    • >>> print('Hello %s, how are you?' % name)
  • When using multiple placeholders, use parentheses and commas to separate them
    • >>> print("Hi %s how is %s" % ("Joe"," Jane"))

strings & variables

  • DON'T FORGET TO USE QUOTES FOR STRINGS
  • If you just put a string without quotes, it'll be read as a variable name
    • Ex. print("Hey Bob") prints the string "Hey Bob"
    • print(Hey Bob) tries to print two variables with the names "Hey" and "Bob"

lists

  • You can create a list object if you want to modify or access specific elements in the list
  • >>> shopping_list = ['eggs', 'milk', 'cheese']
  • >>> print(shopping_list)
  • Access items by using brackets and the index
    • Zero based
    • >>> print(shopping_list[2])
    • >>> shopping_list[1] = 'lettuce'
  • To add to the end of a list, use .append(element)
    • >>> shopping_list.append('chocolate bar')
    • >>> print(shopping_list)
  • Use parentheses instead of brackets to create a tuple
    • Tuples are immutable lists
    • >>> t = (1, 2, 3)

range

  • You can use the range() function to create a list of numbers
    • Put two numbers in the parentheses to create a list from the first number, to the second number minus 1
      • Ex. range(4, 8) == [4, 5, 6, 7]
    • Put one number in the parentheses to create a list from 0 to the number minus 1
      • Ex. range(5) == [0, 1, 2, 3, 4]

slicing lists

  • If you specify the range of indices you want to work with, the list returns only those indices using a colon (:)
  • Like the range function, it's the first number to the second number - 1
    • Ex. players = ["Kirk", "Andrew", "Ross", "Jack", "Ian"]
    • player[0:3] == ["Kirk", "Andrew", "Ross"]
  • It returns a slice of the list!

exercises

Create three variables containing your first name, last name, and age. Then print a string cohesive sentence using all three.

Ex. "Hello, my name is John Headland and I'm 25 years old."

 

Create a list of pizza toppings of at least size 5. Print the message "My pizza has these toppings: " followed by the use of a slice to print the last three items of the list

 

Make a list of 3 people, living or deceased, that you would like to have dinner with. Then you realize your dinner table has grown in size! Append 2 more people to the list.

survey time!

  • Using Chromium, please go to the following url:
    • https://www.surveymonkey.com/r/MK3HTPX
  • Take the survey
Made with Slides.com