LIS-3353 - Command Line
Also — "THE CLOUD"
There is no cloud, it's just somebody elses computer
A computer (possibly virtual), probably running Linux
Yep. Usually.
Funny, it's not talked about that much. Or enough.
Again, not the part that makes people Rich, or even popular
Why do we even use "cloud?"
After all, email is "cloud" and yet we never used that word.
Probably a B2B thing — this was the first time the SERVERS were freed from the bare metal
On Virtual
Many different ways to do "Virtual" and "Virtual-like," but roughly:
VIRTUALIZATION and CONTAINERIZATION
Pure Virtual
- Virtualbox
- VmWare
- KVM
i.e. literally fake the whole computer. You have to install the OS, etc.
Containers
This is "Docker" et al:
You don't fake the whole computer;
you wrap up and "package" the stuff you need to use;
and try to wall it off from everything else.
When you get big, you have to think about this large scale
e.g. KVM
Kubernetes
and other tools for managing A BUNCH OF THESE.
Also, there's the Proton/Wine thing
But may be big in the future in terms of Linux killing windows;
given that games are usually the hardest thing to emulate.
more on containers later...
Shell Scripting - Command line
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."
Names of things
- Command line: Blinky cursor area that's literally asking you, “okay, now what?”
- REPL - Read, Evaluate, Print, Loop. "Programmy" name for the above, you can do this in some "real" languages too, e.g. Python.
- Terminal: App for command line (used to be the computer itself)
- Shell: Any particular “type” of command-line environment. Examples are Bash, Fish, Zsh, MS-Dos, etc.
- Bash: “Bourne Again Shell; the specific Linux/Unix shell we will use. (others are zsh, fish, powershell in windows)
- Scripting: Putting a bunch of shell commands in a file and running it as a program.
Fundamental ideas:
(ignore basic programming ideas like "objects" for now)
- EVERYTHING in the machine is a FILE or FOLDER.
- FILES are made of "TEXT" or "BINARY" * (or some combo-thing)
- SCRIPTING is using TEXT LANGUAGE to do things.
Again
SCRIPTING is as much about
Using programs that ALREADY EXIST TOGETHER
as it is
Making new programs.
("Libraries" on steroids?)
Users and Permissions..
..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
Permissions
Three major things you can do with files
- READ (look at, view, listen to)
- WRITE (and delete and edit)
- EXECUTE (run as a program)
Three important “groups”
- owner of the file
- owner's group
- everybody else
Permissions for Directories
..are weird
- READ: Is able to read the directory listing
- WRITE: Is able to change contents of the directory
- EXECUTE: Is able to access/ go to the director
Practical Permission Problems
- If you're unable to view, execute, or delete/change a file, try this.
- If you write a little shell script (.sh), remember to set it executable. (The only permission command I use on a regular basis is chmod +x “file.sh”
- FAT and NTFS filesystems (the ones Windows use) don't have permissions, but Linux has to occasionally pretend they do, this causes problems.
- When you're taking a website online, this is often a difficult issue. (For a good reason; you don't want website visitors overwriting your critical files!)
A Basic Linuxy Filesystem
- /bin, /sbin – Systemwide binaries
- /boot – Boot Stuff
- /dev - devices
- /etc – (Some) helper files
- /home/user – YOUR files & config (you can just back this up)
- /mnt, /media – generic “mount points”
- /proc – the actual running processes whooa
- /usr – User stuff (mostly binaries)
- /tmp – temp files
- /var – other spooling data, logs
Commands in theory
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
Commands in theory
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.
Commands in Theory
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
two dashes + words (sort --reverse)
Getting Help
- man (command)
- info (might give you more info)
- apropos (keyword to search)
- help (pretty basic stuff)
but seriously, Google/Duckduckgo etc
More
Check out your distro's "Software Center"
and/or
"Package Manager"
File Manipulation
- ls - list
- cd – change directory
- rm –remove (delete for good)
- mv – move OR rename (they are literally the same thing, weird)
- cp - copy
Viewing Text and Files
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
Let's slow down here,
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"
Pipes and Redirects
Default is to read from stdin, and write to stdout.
But by changing the default NOW YOU'RE PLAYING WITH POWER
- > (over)write/replace a file
- >> write to/append to file
- < read from file
- | pipe output from first command into 2nd
- tee pipe AND write to stdout
(interesting then , cat goes from FILE to TEXT, and > goes from TEXT to FILE )
BIG OVERARCHING POINT..
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
BASH (Bourne Again) Shell - others are fish and zsh, etc
Lots of “tricks” are available here, eg
- Tab completion
- Up arrow key for history
- Ctrl-R to search history
and many MANY more...
BASH
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'
Newer Shells
You may see some like
"zsh" or "Zshell"
or Fish
or Oilshell
Roughly, they're a bit nicer to use, but are not "backwards compatible"
which may not matter. Feel free to try them out!
(later on, be careful when NOT using them interactively/as a REPL)
Viewing Files
IN TERMINAL
- less
- cat (stdout)
ALSO
- head and tail
Opening Files
COMMAND/ARGUMENT STYLE
- xdg-open file
- vim textfile
- firefox localfile.html
- firefox http://slashdot.org
Keeping it simple at first:
SORT
sorting text
- -i = case INSENSITIVE
- -r = REVERSE
- -g = numbers
- -R = random
GREP
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)
Classic Bash Commands
- sed
- awk
- find
- locate
Some nicer ones
head
and
tail
for getting only part of a file, by lines
tr
"Transliterate"
Easier way to do SINGLE CHARACTER deletions or transforms
(but can act on "groups," like "A-Z"
cut
Nice way to cut up lines. Just specify the "delimiter"
(the character you'll divide on)
and "which field" by number
echo "first:second:third" | cut -d ':' -f2
yields second
CLI vs GUI
Command Line Interface
vs.
Graphical User Interface
(but, why not both)
CLI, but GUIish
(hardcore nerds may distinguish and call these TUIs)
- Nano
- Midnight Commander
"ncurses"
From CLI to GUI
firefox http://jrm4.com
or
firefox /home/myuser/html/testindex.html
(NOTE, closing the terminal may also close the program)
Backlinks: FSU Courses:LIS3353:Raw LIS3353 Slides