Intro to Command Line
Seth Schoen - Fun with the the Command Line | schoen@eff.org
You can use the command line to control a computer that you aren’t in front of that’s out in the “cloud” or remote. You aren’t limited to just the computer in front of you.
Seth, for example, created accounts through the command line for attendees of the session, on a server that’s actually out in Fremont.
Connectbot for mobile phones
A command line is the textual way to interact with a computer
used to be more popular- was the mainstream way to interact with a computer and now most users rarely, if ever, use the command line.
You get a prompt inside of a terminal and the computer is going to be very persistent
example of a prompt - it is asking you “what do you want to do?” and the computer always wants to know what you want to do.
so type “echo Hello” and it will do that, then give you another prompt asking again
Think of a thing to tell the computer what you want it to do, textually, and then you see results, and get asked again.
Dos is very historically influential here
One thing that’s frustrating is there’s a fairly steep learning curve - because the computer isn’t giving you any hints or help about what to type into the command line that make sense to the computer.
People often learn from books, taking classes, or watching someone else use the command line.
Reasons people like this method: fast don’t have to navigate through menus, can type explicit commands/instructions control - more control and access automation: ie: resizing graphics - the command line can give you a way to act on multiple image files to resize them. very repetitive things can be automated further sense of automation: when you’ve learned lots of commands, you can combine them into scripts, like batch files
I can make a script that does this, then this, then that, all automated and have a name so the computer can do everything for you, in a repeatable way
ie : want to get the audio track from a youtube video
youtube-dl = command that downloads a youtube video
then, get another command to get the audio from the video, and can make a script to get the audio from a youtube video
crosswords puzzle would be available at a known address/predictable url that you could go and download everyday automatically
You can spend any amount of time trying to learn new commands, and the ability to do anything advanced will come with knowing more commands
The power of the command line comes from combining commands
ls = list files wc = word count (count number of words, files, characters)
mkdir secrets cd secrets secrets$ ls secrets$ echo hellp > secret1 secrets$ echo hi > secret2
wc -w secret2 1 secret2
ls | wc -w = “send this thing into that thing” using |
this will get the word count of the list itself - count how many words are in the list
-w is just the number of words, wc gives you the number of files, the number of words, and the number of characters
wc -c = counts the number of characters
the “ - “ is like asking to return just a single “option” instead of all of the options
lot of Unix commands that have to do with referencing text in some way (just to do something relating to text)
Unix for Poets - lecture that starts by introducing the command line in terms of analyzing text like shakespeare, and what are the most frequent words that Shakespeare uses
one command puts every word on a single line by itself one command that will alphabetize the words one command to find out what the most common word Shakespeare used, then the 2nd most common and so forth.
tr ‘ ‘ ‘\n’ | sort | uniq -c | sort -rn
When will we care? When does this come into play where we’d be using this?
many programmers and web developers work with the text of the code of the software they write - web designs are represented textually
Web developers have a lot of concern about searching for things, or making text that’s derived from other text things
Update things automatically
We changed the name of our nonprofit and we have 5000 files on our website and we want to write a script to automate replacing all of the occurrences of the old name with the new one
interface with a flipcam software to get things off it after an update caused problems/failed
If you have a server/computer somewhere not near you - most of the ways you can access the server and enable/configure/change things on that server
CMS - allows you to write text on your website without going through the command line
directories - one important idea, traditional name of what people now call folders, and they organize files
directories come in a hierarchy of inclusion and containment
in an account, you have a directory called your home directory - the main directory of your account. Different from your desktop directory, which is a directory “one level below” your home directory
If you don’t use a command line, you’ll probably not see your home directory much
in a command prompt - you are inside of a directory and your prompt shows you
type pwd : “present working directory” to change directories: cd (change directory) and then type the name of the directory:
cd /home/directory
unix enviroments (MAC OS/X and Linux too) include is a forward slash / dos used a backslash \
so they don’t get along
cd directory without slash
backslash in unix is meaning the item after the backslash
cd / = takes home
Windows has drive letters, Unix doesn’t see this, they see directories hierarchy and place the disk files within the tree instead of drive letters
nothing above the root directory - in computer science, the root of a tree is always way up in the air and everything “grows” down underneath the root
so “go up, go up towards the root” is a different way to think
ls shows you the files and directories that are in the current directory if you don’t specify
type just cd = automatically takes you to your home directory
cd / directory means you want to go into the directory under the root directory
to see many people’s home directories you can type: $ cd /home $ ls
cat = concatenate which means string together
they will come out in the order you ask for them
Create a file:
echo “This is a super-secret.” > secret4 - creates a file called secret4 and the > sign says to send it into a file instead of showing it on the command line. echo just repeats what you type in the command line back to you (or to a file) use quotes to help prevent issues with some punctuation that has a programming meaning
only files one line long - if you want to add additional lines, then you use >> instead of > to add the line to the end of the existing file instead of replacing it.
find out how many words: wc -w secret4
rm = command to remove a file rm secret4
some commands are jokes, terse, many are hard to really remember
rm --help will show information
“--help”
-i
format:
verb -how whatfiles to help you think of writing commands replace the verb, the -how, and the file(s)
{why can’t we use more clear language in the command prompt/line?}
mv = “rename”
what if I wanted to move something from a directory into another directory
mv whatfiles /home/userhome if you start to type a file name and press tab, then the system will try to find one for you
cp secret2 secret3
copies secret2 into secret3
modify ls to be more detailed: ls -L (for “long” not capitalized)
The surprise for most people with command lines is that there is no “undo” option - if you move or delete something then that’s it, you can’t change it back (not easily at all)
so some people will have version control software and that helps manage different versions you can also get options that change colors, theme so to speak, and
convention :
..
meaning the parent directory (one directory above this one)
git log = show all the changes that have happened on this project, who made it, and when
and git has a command to go back and get the old/previous version
resources: Seth’s book write to Seth and request his book and he wants feedback because it’s meant for beginners
Floss manuals introduction to the Command line
more - let’s you see a long file one string/line at a time so someone wrote another version and called it less
- = comment and not a command