2/24/2014
Presented by Austin Parker | @austinlparker
Early computers used physical switches and printed cards as an interface. The command-line interface became popular in the mid-1960's as video displays were popularized. Since then, the CLI has remained a powerful, fast, and efficient interface for computing.
Interpreter (shell)
The software that implements the text interface to the computer.
Prompt (command prompt)
The current context for interaction with the interpreter.
ITS Unix : unix2%
Raspbian : pi@raspberrypi ~ $
Command
An instruction given by the client (that's you) to the interpreter. It's like tapping on an app to open it, except much less visually stimulating.
Parameter
Optional instructions as part of a command. Parameters generally fall into two categories, arguments and options
Syntax
The grammar that commands to the shell must follow, differs between operating systems and applications.
unix2% mkdir foo
prompt - command - argument
unix2% rm -rf ~/path/to/foo
prompt - command - options - argument
In the first example, mkdir is the command and foo is the argument. We want to make a directory named foo.
In the second, rm is the command, r and f are the options, and ~/path/to/foo is the argument. We want to delete the directory foo and all of its subdirectories
Files and Directories
ls cd pwd mv mkdir rm cat touch
Going Everywhere, Doing Things
ssh scp wget chmod chown grep tar
Editing Files and Getting Help
nano pico vim emacs man
bash (Linux, MacOS)
bash (an acronym for bourne-again shell) was released in 1989 and remains one of the most widely used shells - It is a replacement for the Unix standard Bourne shell. Useful features include command history and automatic command completion (tab-completion).
zsh (Linux)
zsh was written in 1990, and it extends many common Bourne shell features while mixing the best of bash, ksh, and tcsh. The main improvements over bash are a deeper command-line completion algorithm, shared command history across multiple running shells, improved handling of arrays and variables, spell check, and more customization. Find it at SourceForge
PowerShell (Windows 7+)
PowerShell was first released in 2006 and is a powerful tool for scripting and working with Windows services and applications such as Windows Server, Outlook, and the WMI. A discussion of PowerShell is beyond this lecture, please visit this wiki for more information.
PuTTY (Windows, Linux)
PuTTY isn't actually a shell, it's a terminal and serial emulator. PuTTY and its forks are the preferred method to communicate via ssh to remote servers, but it supports many more. It's relevant because to many people, PuTTY is their only real window into the terminal, so it's something you'll be using a lot if you primarily work with Windows.
I/O Redirection and Pipes
ps aux | grep 'apache'
The pipe |
in bash instructs the shell to send the output of the first command as the input of the second.
grep file.txt 'foo' > outfile.txt
exampleprogram < infile.txt
The carets <
and >
direct the input to a command be from a file, or the output to a file, respectively.
Terminal Multiplexing
tmux ls
tmux -s <session>
tmux att -t <session>
Terminal Multiplexing is offered by programs such as tmux
and screen
, the full scope of which is beyond this lecture. The basic concept, however, is that you are able to split your terminal into multiple separate windows that you can move between and save your work as you go. This is very handy to run on remote servers, as if your connection is interrupted, you won't lose all your work!
You can find more information about tmux at its download page. A command reference is located here.
Everyone on a computer has a unique username. At UA, this is your NetID, but you also set one up for your MacBook or Windows Laptop.
Behind the scenes, these unique usernames (and groups) determine what files you have access to. We can view this on ITS Unix with the ls -l
command at a prompt, a sample output of which is below.
unix2% ls -l
total 92
-rwx------ 1 ap413335 student 17012 Nov 4 13:13 a.out
-rw------- 1 ap413335 student 4020 Jan 22 18:20 cable2.c
drwx--S--- 4 ap413335 student 512 Nov 8 14:40 CSI310
drwx--S--- 8 ap413335 student 512 Nov 22 09:12 CSI333
drwx--S--- 4 ap413335 student 512 Feb 9 12:44 CSI402
drwxr-sr-x 2 ap413335 student 512 Sep 6 13:46 flocking
-rw------- 1 ap413335 student 0 Nov 4 13:10 outfile
So, if we wanted a HTML file to be readable by the webserver, it's permission flags would need to look like...
-rw-r--r-- ... baz.html
We can set that state with the following command...
chmod 644 filename
Connect to a host
ssh username@host
Copy a file from remote to local
scp username@host:filename /local/path
Copy a file from local to remote
scp filename username@host:/remote/path
Copy a directory from local to remote home
scp -r dir username@host:~
Move a file from one place to another
mv filename /new/path
Change a file name
mv filename new_filename