Let’s start with what Linux build to get, if you want to follow along.
In the videos below, the Hak5 presenter appears to have used Ubuntu (www.ubuntu.com) for this article. The download of the .ISO file is free. It is also big. The 20.04 desktop version is about 1.4 Gigs.
Once the .ISO is downloaded, then you have the choice of creating a bootable USB stick, installing on a stand alone machine, or installing the system as a Virtual Machine.
Look here (http://www.omgubuntu.co.uk/2016/04/how-to-create-a-bootable-ubuntu-usb-on-windows-mac-and-linux) for how to create a bootable USB on Windows, MAC, or Linux machine.
Look here (https://ubuntu.com/tutorials/how-to-run-ubuntu-desktop-on-a-virtual-machine-using-virtualbox#1-overview) for how to install Ubuntu as a virtual machine using free Virtual Box.Once you have your Ubuntu Linux machine ready, let’s begin this mini-course.
Start here:
-
date – displays date
-
cal – displays the calendar
-
df – displays used and available space on the disk system
-
free – displays free space
-
pwd – print working directory
-
cd – change directory, a series of options was shown
-
ls – list contents of a directory, and several options were shown
-
not mentioned was the ‘dir’ command which shows all files in the current diretory
-
clear – clears the terminal screen
-
adding ‘–help’ on the back of any command displays the linux help for that command
Linux Terminal 101 – File Manipulation
-
mkdir – creates a new directory
-
rmdir – removes a directory (this was not mentioned in the video)
-
cp – copy a file, a source to a destination
-
mv – move – you can move a file to a directory or to a copy of the original file
-
rm – removes a file or directory (be careful!)
-
do not forget the ‘–help’ on these commands to see many options available
Linux Terminal 101 – Wildcards, Hard Links, and Symbolic Links
-
examples start at about the 2 minute mark
-
using a “*” in a command is a wildcard that matches any characters – such as ‘ls *’
-
using a “?” in a command is a wildcard that matches any specific character in that position – such as ‘ls Test?’ will match all files that start with “Test” and have a single character following that word.
-
using a bracketed letter or sequence shows all items with that sequence. For example in a directory with Test1, Test2, Test3 and Test4 files, if you enter ‘ls Test[1]’ only the Test1 file will be shown.
-
putting a ‘!’ in the brackets is the same as “not”. For example in a directory with Test1, Test2, Test3 and Test4 files, if you enter ‘ls Test[!1]’ all but the Test1 file will be shown.
-
using double brackets ‘[[:st]]’ creates a way to find anything matching the characters used
-
ln – link – creates a hard link to a file or directory.
-
The presenter makes reference to an explanation of hard vs. soft links but never shows it. We recommend this one: http://www.geekride.com/hard-link-vs-soft-link/
-
-
do not forget the ‘–help’ on these commands to see many options available
Linux Terminal 101 – Filenames, History, and Shortcuts
-
history – shows history of commands
-
history | less – shows history on a page by page basis (space moves forward a page, q quits)
-
!! – reruns last command used, and !5 would run the 5th command in the history (5 commands ago). But, as shown, most of us simply use the up arrow. The up and down arrow allows you to navigate the history
-
the tab key is the autocomplete
Linux Terminal 101 – type, which, and apropos
-
type – tells what type of command or term is in Linux
-
which – tells which area in Linux the command is referenced from
-
man – internal manual pages for Linux
-
apropos – searches the manual for all instances of a term
-
whatis – asks Linux what a term/command is
-
info – finds information on a term/command in the manual
Linux Terminal 101 – Create your own command with alias
-
the ‘;’ allows you to string together commands
-
alias – allows you to create commands or stringed commands – as shown use ‘type’ and the alias name to display the command contents. Remember that alias commands are not saved.
-
unalias – removes an alias
-
To save aliases for future use, you have to edit the .bashrc file.
-
Here is a nice alias: alias upd=’sudo apt-get update;sudo apt-get upgrade’
Linux Terminal 101 – I/O Redirection
-
normal output goes to ‘stdout’
-
errors go out to ‘stderr’
-
the command Shannon used was ‘ls -l /usr/bin > ls-output.txt’ The redirections essentially performed by the “>”.
-
the second command used was ‘ls -l /usr/bin >> ls-output.txt’ prepends the output onto prior file.
Linux Terminal 101 – Redirecting Standard Terminal Errors
-
remember errors go out to ‘stderr’
-
the command Shannon used was ‘ls -l /bin/usr 2> ls-error.txt’ The redirections if the errors essentially performed by the “2>”.
-
the second command used was ‘ls -l /bin/usr > ls-output.txt 2>&1’
-
the third command used was l’s -l /bin/usr &> ls-output.txt’
-
We don’t reccomend the last command she shows – errors are important – but here it is: ‘ls -l /bin/usr 2> /dev/null’
Linux Terminal 101 – Using CAT with Standard Inputs
-
cat is like ‘type’ in DOS
-
cat lists the contents of a file: ‘cat ls-output.txt’
-
cat Test* > JoinedTest would join all Test files in order.
-
Creating a text file with cat: cat >file.txt and then start typing the text you want to see in the file.
Linux Terminal 101 – Grep and Pipes
-
‘|’ is the pipe command (look above your backslash key) means the output of the left of the pipe is redirected to whatever is on the right, and you can create a chain of multiple pipes.
-
Example 1: ls -l /usr/bin | less
-
Example 2: ls /bin /usr/bin | sort | less
-
Example 3: ls /bin /usr/bin | sort | uniq | less
-
Example 4: ls /bin /usr/bin | sort | uniq -d | less
-
Example 5: wc trust.txt
-
Example 6: ls /bin /usr/bin | sort | uniq | wc -l
-
grep finds files and text with certain patterns.
-
Example 7: ls /bin /usr/bin | sort | uniq | grep zip
-
Example 8: head -n 5 trust.txt
-
Example 9: tail -n 5 trust.txt
-
Example 10: ls /usr/bin | tail -n 5
-
Example 11: ls /usr/bin | tee ls.txt | grep zip