A Unix "shell" is a command-line interpreter that provides a traditional user interface for the Unix operating system and for Unix-like systems.
- There are a bunch of different shells... Bourne shell, C shell, Korn shell, Z shell, etc.
- The first major shell was the Bourne Shell, developed in the late 70's.
- We're going to focus on the "Bourne again shell" or Bash (default shell for OSX and Linux)
Hint: You can install Bash bindings in Windows via Git for Windows
- A fully-capable scripting language
- Vast adoption (approximately 70% of public servers are Unix or Unix-like)
- Tons of command line features...
- Tab completion
- Pipes
- Aliases
- Environment variables
- Startup scripts
- ...and more!
In this next part, we'll learn some basic commands that we can use to interact with our Bash shell.
The outline below is provided as a handy reference of the commands we'll cover in class. This tutorial contains alot of additional information if you're confused or just curious.
pwd
- Display your "present working directory".
ls
- Display the contents of a directory specified by <path>
.
Optional Flags:
Long listing (with details)...ls -l
List all files...ls -a
Optional Arguments:
Apply to files or directories...ls <path>
Hint:
You can use the wildcard character too...ls *.txt
cd
- Change to directory specified by <path>
Optional Arguments:
The location to move to...cd <path>
Special Characters:
Move to the parent directory...cd ..
Return to previous working directory...cd -
Root of filesystem...cd /
Your home directory...cd ~
orcd --
curl
- Download a file.
Required Arguments:
File url...curl -O <url>
Hint:
Try executing this...curl -O https://github.com/git/git/blob/master/Documentation/giteveryday.txt
cat
- Concatenate and print files
Required Arguments:
The file to concatenate...cat <file>
Hint:
Path multiple paths to concatenate files...cat <file> <file>
Special Characters:
Send output to a new file...cat file1.txt file2.txt > combined.txt
Wildcards...cat *.txt > all-the-files.txt
head
- Show the first ten lines of a file.
Required Arguments:
The file to display...head <file>
Optional Flags:
Specifyn
lines...head -n 25 <file>
tail
- Show the last ten lines of a file.
Required Arguments:
The file to display...tail <file>
Optional Flags:
Specifyn
lines...tail -n 25 <file>
mkdir
- Make a new directory.
Required Arguments:
The name of the new directory...mkdir <name>
Optional Flags:
Create intermediate directories as required. ...mkdir -p <path>
mv
- Move (or rename) a file or directory
Required Arguments:
The target and destination...mv <target> <destination>
cp
- Copy a file or directory
Required Arguments:
The target and destination...cp <target> <destination>
Optional flags:
Copy recursively (directories)...cp -R
rm
- Remove files and directories
Required Arguments:
The file or directory to remove...rm <path>
Optional Flags:
Remove recursively (directories)...rm -r
open
- View directory or file specified by <path>
.
Required Arguments:
Directory or file...open <path>
Special Characters:
A dot character refers to the current directory...open .
Note For Windows Users...
Use this command instead...explorer .
man
- Display documentation for a given command. "Man" is short for "manual".
Required Arguments:
The command to display documentation for...man <command>
Hints:
Exit a man page by pressing the 'q' key on your keyboard.
Note For Windows Users...
Use this command instead...help
or--help
history
- Show command history
Special Characters:
Recall previous command...!!
Repeat command in your history...!<linenumber>