The Unix Command Line
This section uses material compiled by Brian O’Shea for his ICP 490 class at MSU.
The program that provides the command line (not all of the commands) is the shell. A common shell is
> man bash. The command line is a unix process. Launching a command on the command line interface (CLI) spawns a child process.
- you will need a terminal command line editor without GUI, such as
- cat, touch
- cp, rm
- wc (-l)
- ls (-l, many other options)
- cd (. or .. or ~ or actual directory)
- mv (works on files and directories)
- du (-sh)
- df (-h)
|pipes and filters: use
||to pipe between command, use > to redirect output
Customizing your CLI
You can define variables and aliases in the .bashrc file. The details on how this is set up depends on the particular Linux/Unix/Mac flavour.
- environment variables
You can combine a sequence of shell commands into a file and use as a shell script. You have to make the file with the script executable (
chmod u+x file_name.sh). See file
example.sh in the example directory.
You can find numerous online tutorials and support resources on the internet, such as (search yourself for other and let us know what you find useful) [last updated: 01/2015]:
These tutorials may differ in which shell and/or command line editor they us. Don’t get confused by that.
- create a directory and go into it
- create a text file (with touch), edit it with the CLI editor of your choice to fill it with the names of lots of people you know
- move the file to another name.
- how many lines does it have?
- search through the file for all incidences of a particular letter or string, and count them with ‘wc’
- use ‘man’ to look at the various options for ‘grep’, and then look for lines that do NOT have the letter ‘e’ in it.
- go up one directory, and use ‘du -h’ on 1) the entire directory tree, and 2) just the new directory.
- use ‘man’ to look at the options for ‘rm’, and then delete ONLY the entire directory you just created in one command.
- use ‘history’ to see what you just did!