An Overview
We will be covering the following in the workshop today:
- Downloading and installing VirtualBox
- Downloading, installing, and setting up Ubuntu 16.04 LTS
- Short history of Linux OS and what is being done with it today
- Sudo (and a security warning...)
- Directories
- Terminal / command line
- Fun terminal things! (like cowsay, fortune, Star Wars, cmatrix...)
Dr. Bowring also gave me a link for FREE Linux ebooks to pass along to all of you! I downloaded "Learn Linux in 5 Days". Here is the link. Other ones were "Crypto 101" and "Linux Networking Cookbook". I am just going to repeat that these are free!
Set Up a Virtual Machine
What is a virtual machine?
A virtual computer system is known as a “virtual machine” (VM). It is a tightly isolated software container with an operating system and application inside. ... Putting multiple VMs on a single computer enables several operating systems and applications to run on just one physical server, or “host”. ~www.vmware.com
VirtualBox (5 min)
There are many other options for virtualization (such as VMware), but we will be using VirtualBox. VirtualBox is free and open source software, but it's quality is monitored by Oracle (Oracle is known for its relational database software, the first to support the SQL language, which has since become the industry standard).
According to their VirtualBox's website: "VirtualBox is a community effort backed by a dedicated company: everyone is encouraged to contribute while Oracle ensures the product always meets professional quality criteria."
TO DO:
Go here and download and install VirtualBox 5.1.
Ubuntu 16.04 LTS (15 min)
There are many many "flavors" of Linux, but we will be using Ubuntu because it is very easy to get started with (and at least it has a GUI).
TO DO:
Go here and scroll to where it says:
Your download should start automatically.
A Little Bit of History (15 min)
"If I have seen further it is only by standing on the shoulders of giants." (~ Isaac Newton - phrase also used by Bernard of Chartres, Stephen Hawking...)
What is an OS?
An operating system (OS) is system software that manages computer hardware and software resources and provides common services for computer programs. All computer programs, excluding firmware, require an operating system to function. [1]
It all began with UNIX...
UNIX is an operating system that originated at Bell Labs in 1969 as an interactive time-sharing system. Ken Thompson and Dennis Ritchie are considered the inventors of Unix. [2]
GNU -> GNU / Linux
The GNU Project is a free-software, mass-collaboration project, first announced on September 27, 1983 by Richard Stallman at MIT. Its aim is to give computer users freedom and control in their use of their computers and computing devices, by collaboratively developing and providing software that is based on the following freedom rights: users are free to run the software, share it (copy, distribute), study it and modify it. [3]
What does sudo mean? (5 min)
Sudo is an abbreviation of “super user do” and is a Linux command that allows programs to be executed as a super user (aka root user) or another user. It's basically the Linux/Mac equivalent of the runas command in Windows. [7]
Sudo gives us safe elevated privileges when we want to run important commands. It might be THE most used and powerful command among Ubuntu users, as it has become the preferred method in that distribution. Now that you have the power, be sure to be safe when you issue your commands! There is no su-undo! [8]
TO DO: Open the Terminal and Become the Root User
# Type this into the Terminal then enter your password sudo su # If the # mark appears, then you were successful!
Linux Terminal Commands (~45 min total)
I made a folder with some text files to practice with! Go and download this folder to get them.
Linux allows you to access all files in your directory (especially if you are the super user)!
Examples of common folder names:
/bin Binaries and other executable programs.
/etc System configuration files.
/home Home directories.
/opt Optional or third party software.
/tmp Temporary space, typically cleared on reboot.
/usr User related programs.
/var Variable data, most notably log files.
Directory Shortcuts
Directories are simply containers for files and other directories. They provide a tree-like structure for organizing the system. Directories can be accessed by their name and they can also be accessed using a couple of shortcuts.
. This directory.
.. The parent directory.
/ Directory separator. Directories end in a forward slash and this is often assumed.
Folder Structure for Downloaded Files
Basic Commands
ls - Lists directory contents. You will use ls to display information about files and directories.
cd [dir] - Changes the current directory to dir. If you execute cd without specifying a directory, cd changes the current directory to your home directory. This is how you navigate around the system.
pwd - Displays the present working directory name. If you don't know what directory you are in, pwd will tell you.
cat [file] - Concatenates and displays files. This is the command you run to view the contents of a file.
echo [argument] - Displays arguments to the screen.
man - command that displays the online manual for command. Type q to quit viewing the manual page. The documentation provided by the man command is commonly called "man pages."
exit, logout, or Ctrl-d - Exits the shell or your current session.
clear - Clears the screen.
Making and Removing Directories
The mkdir command is used to create directories and the rmdir command removes them.
mkdir [-p] directory - Create a directory. Use the -p (parents) option to create intermediate directories.
rmdir [-p] directory - Remove a directory. Use the -p (parents) option to remove all the specified directories. rmdir only removes empty directories. To remove directories and their contents, use rm.
rm -rf directory - Recursively removes the directory and all files and directories in that directory structure. Use with caution. There is no "trash" container to quickly restore your file from when using the command line. When you delete something, it is gone.
In Linux, you can find specific programs and see how they work!
An example:
If you want to know exactly where a command is located you can use the which command. If the program cat is located in /usr/bin and in /usr/local/bin, the one which will get executed depends on your $PATH.
$ which cat /bin/cat $ which tac /usr/bin/tac
Viewing and Editing Files
Here are some simple commands that display the contents of files to the screen.
cat file - Display the entire contents of file.
more file - Browse through a text file. Press the Spacebar to advance to the next page. Press Enter to advance to the next line. Type q to quit viewing the file. Commands are based on the vi editor, which is covered in the next section.
less file - Like more but allows backward movement and pattern searches.
head file - Output the beginning (or top) portion of file.
tail file - Output the ending (or bottom) portion of file
Comparing Files
diff file1 file2 - Compare two files.
sdiff file1 file2 - Compare two files side by side.
Finding or Locating Files
find . -name pattern - Displays files whose name matches pattern. This is case sensitive.
locate pattern - List files that match pattern
Searching for Text in ASCII Files
If you are looking for text within a file, use the grep command.
grep pattern file - Search for pattern in file.
grep -v pattern file - Invert match. Return lines from file that do not match pattern.
Here are some more common options to use with grep.
grep -i - Perform a search, ignoring case.
grep -c - Count the number of occurrences in a file.
grep -n - Precede output with line numbers from the file.
Using Cut
cut [file] - Cut out selected portions of file. If file is omitted, use standard input.
cut -d delimiter - Use delimiter as the field separator.
cut -f N - Display the Nth field.
Pipes and Piping
You will notice that two commands have been chained together with a vertical bar, also known as the pipe symbol. The pipe ( | ) means take the standard output from the preceding command and pass it as the standard input to the following command. If the first command displays error messages those will not be passed to the second command.
Try combining cut and piping | ...
Deleting, Copying, Moving
rm file - Remove file.
cp source_file destination_file - Copy source_file to destination_file.
mv source destination - Move files or directories. If destination is a directory, source will be moved into destination. Otherwise source will be renamed to destination.
Sorting
sort file - Sort text in file.
sort -r file - Sort in reverse order.
sort -u file - Sort text in file, removing duplicate lines.
Fun Linux Terminal Things!
Finally! Now to the fun stuff! You can copy and paste the following lines of code to install and run some of these awesome applications created by fellow Linux users.
How about a rainbow cow that tells you your fortune?
# Install Cowsay sudo apt-get install cowsay # Install Fortune sudo apt-get install fortune # Install Ruby and Gems sudo apt-get install ruby-full # Install Lolcat sudo gem install lolcat # Run it! fortune | cowsay | lolcat
Or a dragon?
# Install Git
sudo apt-get update apt install git
git log -1 | cowsay -f dragon-and-cow | lolcat
Or a sheep?
cowsay -f sheep have fun guys!
Or a stegosaurus?
cowsay -f stegosaurus hi!
Ascii Star Wars in the Terminal
# Simply paste this into the Terminal telnet towel.blinkenlights.nl
Asciiquarium - My Favorite!
# Paste the following into the Terminal sudo apt-get install libcurses-perl cd /tmp wget http://search.cpan.org/CPAN/authors/id/K/KB/BAUCOM/Term-Animation-2.4.tar.gz tar -zxvf Term-Animation-2.4.tar.gz cd Term-Animation-2.4/ perl Makefile.PL && make && make test sudo make install cd /tmp wget http://www.robobunny.com/projects/asciiquarium/asciiquarium.tar.gz tar -zxvf asciiquarium.tar.gz cd asciiquarium_1.0/ sudo cp asciiquarium /usr/local/bin sudo chmod 0755 /usr/local/bin/asciiquarium # Now run it! /usr/local/bin/asciiquarium
The Matrix Screen - cmatrix
# Type this sudo apt-get install cmatrix # Run! cmatrix
sl - Steam Locomotive Accident
sudo apt-get install sl # To run sl # So when you try to do ls and accidentally type sl, you will now get a train!