....cybersecurity edition
At a point in history, this was the ONLY
way to interact with the computer
AND
The "users" were the "programmers"
NO HAND HOLDING
That default thing that comes up on all the unixy-linuxy systems everywhere.
It’s a text interface. You type commands into it and the computer responds.
And it’s also a "programming" language. As in, you can type in more than one command in a row, save it to a file, and run the file. So, you know, "programming."
..actually mean something today
ROOT – Like “Administrator” or maybe “God”
users – humans
(..and others – fake “users” to get tasks done)
Some systems (eg Ubuntu) allow for Super Users
S.U.- do “this” = sudo
Three major things you can do with files
Three important “groups”
..are weird
Any IMPERATIVE action the computer can do. Can be one word or more.
Ultimately, will be an ORDER, usually expressible as a VERB
Are VERY closely related to (if not identical) to FUNCTIONS/METHODS
"Computer! Do THIS!"
ls
Since we're in the command line we are always acting on:
FILES and/or TEXT. These will be input and/or output.
if commands are VERBS, the FILES and TEXT are the nouns/objects
We call these expressions
(and of course, the TEXT can lead you to something else, like a FOLDER)
cat file.txt echo "Hi there" ls "/home/mine"
Nearly every command can act on either TEXT or FILES or BOTH.
We've talked VERBS and NOUNS. But we might want to modify the operation of things;
Think ADVERBS and/or ADJECTIVES:
On the command line, these are called options
but seriously, Google/Duckduckgo etc
cat - "Good" example of "efficiency" at the expense of "redundancy"
i.e. it means "concatenate" — which is to squish two files together and print to the screen. But it can also do it with just one file.
less - this is such a terribly bad joke I hate even explaning it
because here is the power:
One way to describe cat - It "shows you the file"
BUT, let's be VERY precise here:
Cat TAKES A LINE OF TEXT (that refers to a file)..
and PRINTS IT ON THE SCREEN
TAKES A LINE OF TEXT = "Standard Input or stdin"
PRINTS IT ON THE SCREEN "Standard Output or stdout"
Default is to read from stdin, and write to stdout.
But by changing the default NOW YOU'RE PLAYING WITH POWER
(interesting then , cat goes from FILE to TEXT, and > goes from TEXT to FILE )
THAT'S MY OPINION
If it works and its clearer to you, don't let the supernerds tell you it's a bad idea e.g.
"Useless use of cat" IS FINE
BASH (Bourne Again) Shell - others are fish and zsh, etc
Lots of “tricks” are available here, eg
and many MANY more
Furthermore, you can modify this environment to fit your needs, via:
.bashrc
(stuff here will be run everytime you open a terminal)
A great example is the “alias” command. If a command doesn't exist for what you want to do, just ,ake up your own!
alias modbash='nano ~/.bashrc'
IN TERMINAL
ALSO
COMMAND/ARGUMENT STYLE
Thinking about these tools re: cybersecurity, you're likely not looking at prose or code, but "data," often tabular or otherwise "organized."
sorting text
searching text for matches
grep OPTIONS PATTERN (FILE)
Can search over FILES or STDIN
Also, can search ONE FILE or MANY (check -d or -R)
useful flags:
-i (case insensitive)
-v (invert search/show NON-matches)
-l (just show matching FILES, not lines)
(see also "ripgrep" or rg)
Searches directory tree rooted at given filename (default current)
Good if you also want to use parameters like “date”, “last accessed”, “size” and so forth.
Often used with -name or -iname
Also, consider “locate” (database must be setup beforehand)
but what if we want to change the text?
Remember, this is relatively easy and non-destructive by default; most of the time we're NOT changing the file in place, we're printing to stdout and optionally saving that output:
SED and AWK
You can do A LOT with these, they're basically languages in their own right. They're a little difficult, especially AWK.
echo “Good day” | sed 's/day/night/'
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/sed1line.txt
awk <search pattern> {<program actions>}
Also a text-processor, good for flat-file databases
Also, an entire language
awk ' /apples/ { print $2 “ “ $1 } '
Transliterate, i.e.
CHANGE a character to another
(yes, this is how I did JOHN IS RAD)
tr [a-z] [A-Z]
cut a string according to, e.g. fields
(this is my favorite. I just find it way more intuitive than awk/sed)
-f = which field or fields and optionally
-d = change the delimiter
e.g. to get the last name:
cut -f2 -d " "
-> ...combine with the following
Is for "word count" — but it can do newline and byte counts.
Since bash can do a lot of "by line" stuff, wc -l
might be valuable
(again, a lot of these tools have "count" built in, but I find this easy to remember)
hey, it's a command. Can tell you about a file
exiftool
- (grab data from pictures)
strings - (Look for human readable strings in anything)
zipping and unzipping generally (try it on a docx or odt ☺ )