The Command Line

A long time ago computers didn’t use a mouse and windows, the only way to work with them was using the keyboard and writing text. Now days that is not the case and most software you use will have a Graphical User Interface (GUI). This interface has menus that allow you to do things you want to do. But the old way of using a computer still exists and can be useful in many situations. The main advantage of the command line is that you can type thousands of words, many more choices then you could see on a menu. The main disadvantage is that you probably don’t know or want to know a thousand commands for your computer. However, once you know some commands it can be much faster to access them through the command line than a menu, and many commands can only be accessed through the command line.

Terminal

First you will need to run a program that emulates a terminal. There are many choices for this, the default on Mac OS X is called terminal. On Windows if you want to run Anaconda Python you should use the Anaconda Prompt. With Windows 10 you can also install a linux bash shell to run on your machine. Instructions.

The terminal is a screen that shows only text and you can only enter it at one place called the prompt. At the prompt you enter commands that are like words, though many commands aren’t actual words. Many commands can be modified with flags. Flags start with a – or –. Most commands have a help flag so
command --help
command -h
will often print help about the command. Also there is a command man, for manual, that prints help about the command. And of course there is the internet. Also many commands take arguments like the name of a file. Spaces go between each command, flag and argument. And finally one needs to hit enter to execute the command.

Unix Commands

There are thousands of commands in a standard unix distribution, you’ll only end up learning the few you find useful. Every command also has many options, usually given with a flag that start with a – or a –. Use man or the web to get a description of all the options. Below are some commands that I have found useful.

command > file redirect, >, sends what would be printed to the terminal instead to file, more options here
cd dirname change directory, .. is up one directory and . is the current directory
chmod filename changes the permissions of a file, u,g,o +/- r,w,x
chown user filename changes the owner of a file to user
cp filename1 filename2 copies filename1 to filename2
du dirname gives the amount of memory (disk usage) of the directory (or all files if no dirname is given)
emacs -nw filename opens filename with emacs in the in the terminal (emacs must be installed)
grep string filenames grep will search for the given string in a file
head -N filename prints the first N lines of a file in the terminal
less filename displays the text of a file in a the terminal
ls list the contents of a directory, -a will list .files, -l will give more information
man command prints the manual page of the command in the terminal
mkdir dirname makes a directory names dirname
more filename displays the text of a file in the terminal
mv filename1 dirname moves a file to a different directory or renames it dirname if not a directory
nohup command nohup before a command insures that the process won’t be killed if you kill the window
pwd the present working directory is printed in the terminal
rm filename removes a file permanently
scp filename hostname:filename copies a file securely to or from a remote machine
ssh user@hostname logs a user into a remote machine
ssh-keygen -t rsa/code> generates a private/public key pair using rsa encryption
ssh-copy-id -i hostname copies the key to a remote host (not installed on OSX use homebrew)
tail -N filename prints the last N lines of a file to the terminal
top prints the top jobs running on the cpu and information about them
vim filename opens filename in the vi text editor in the terminal
wc filename word count of filename, gives characters, words and lines
which command gives full path of command
Print this page