So often we use Linux as a virtual machine or even as a test or capture system. If you are a little rusty on Linux, or brand new to it, there is a lot to learn.
This article is like a mini starter course on Linux. I have built this mini course by condensing some oldie but goodie HakTip videos from the folks at Hak5 along with out own notes on using Linux.
Once you have your Ubuntu Linux machine ready, let's begin this mini-course.
Start here:
Here is a summary of the commands presented:
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
Here is a summary of the commands presented:
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
Here is a summary of the commands presented:
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.
do not forget the '--help' on these commands to see many options available
Linux Terminal 101 - Filenames, History, and Shortcuts
Here is a summary of the commands presented:
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
Here is a summary of the commands presented:
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
Here is a summary of the commands presented:
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
Here is a summary of the commands presented:
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
Here is a summary of the commands presented:
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
Here is a summary of the commands presented:
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
Here is a summary of the commands presented:
'|' 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
I hope you find this mini course/article and its content helpful. Comments are welcomed below. If you would like to see more articles like this, please support us by clicking the patron link where you will receive free bonus access to courses and more, or simply buying us a cup of coffee!, and all comments are welcome!