Skip to content
This repository has been archived by the owner on Jan 3, 2018. It is now read-only.

Commit

Permalink
Adding shell cheat sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
gvwilson committed Nov 30, 2013
1 parent 697d492 commit 5159f8a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions bash/novice/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Topics
See Also
--------
* [Instructor's Guide](guide.html)
* [Reference](reference.html)

Resources
---------
Expand Down
53 changes: 53 additions & 0 deletions bash/novice/reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
layout: lesson
root: ../..
title: Shell Reference
level: novice
---
Basic Commands
--------------
* `cat` displays the contents of its inputs.
* `cd path` changes the current working directory.
* `cp old new` copies a file.
* `find` finds files with specific properties that match patterns.
* `grep` selects lines in files that match patterns.
* `head` displays the first few lines of its input.
* `ls path` prints a listing of a specific file or directory; `ls` on its own lists the current working directory.
* `man command` displays the manual page for a given command.
* `mkdir path` creates a new directory.
* `mv old new` moves (renames) a file or directory.
* `pwd` prints the user's current working directory.
* `rm path` removes (deletes) a file.
* `rmdir path` removes (deletes) an empty directory.
* `sort` sorts its inputs.
* `tail` displays the last few lines of its input.
* `touch path` creates an empty file if it doesn't already exist.
* `wc` counts lines, words, and characters in its inputs.
* `whoami` shows the user's current identity.

Paths
-----
* `/path/from/root` is an absolute path.
* `/` on its own refers to the root of the filesystem.
* `path/without/leading/slash` is a relative path.
* `.` refers to the current directory, `..` to its parent.
* `*` matches zero or more characters in a filename, so `*.txt` matches all files ending in `.txt`.
* `?` matches any single character in a filename, so `?.txt` matches `a.txt` but not `any.txt`.

Combining Commands
------------------
* `command > file` redirects a command's output to a file.
* `first | second` connects the output of the first command to the input of the second.
* Use a `for` loop to repeat commands once for every thing in a list:

for variable in name_1 name_2 name_3
do
...commands refering to $variable...
done

* Use `$name` to expand a variable (i.e., get its value).
* Use `history` to display recent commands, and `!number` to repeat a command by number.
* Use `bash filename` to run commands saved in `filename`.
* `$*` refers to all of a shell script's command-line parameters.
* `$1`, `$2`, etc., refer to specified command-line parameters.
* Use `$(command)` to insert a command's output in place.

0 comments on commit 5159f8a

Please sign in to comment.