X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=shell_cheatsheet.md;h=df2185534ff8ffa091b6d4f7d4ce64204107d9b9;hb=2bc70b45357e5eb4132b570f82353268dfbc695e;hp=2b1ebcce546e9877c261bfadb52e111fdcf4dcea;hpb=a3ffffb23d73c40a55c214c62ffc329807bc07c5;p=swc-modular-shell-hearing.git diff --git a/shell_cheatsheet.md b/shell_cheatsheet.md index 2b1ebcc..df21855 100644 --- a/shell_cheatsheet.md +++ b/shell_cheatsheet.md @@ -3,7 +3,7 @@ ## 1. Shell Basics: -| Symbol | Definition | +| Command | Definition | |----------------|----------------------------------------------------------------------------------------------------------------| | `.` | a single period refers to the current directory | | `..` | a double period refers to the directory immediately above the current directory | @@ -16,27 +16,36 @@ ## 2. Creating Things: ### a) How to create new files and directories.. - -`mkdir ./dirname` | makes a new directory called dirname below the current directory. _Note:_ Windows users will need to use `\` instead of `/` for the path separator -`nano filename` | if `filename` does not exist, `nano` creates it and opens the `nano` text editor. If the file exists, `nano` opens it. _Note:_ _(i)_ You can use a different text editor if you like. In gnome Linux, `gedit` works really well too. _(ii)_ `nano` (or `gedit`) create text files. It doesn't matter what the file extension is (or if there is one) +| Command | Definition | +|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `mkdir ./dirname` | makes a new directory called dirname below the current directory. _Note:_ Windows users will need to use `\` instead of `/` for the path separator | +| `nano filename` | if `filename` does not exist, `nano` creates it and opens the `nano` text editor. If the file exists, `nano` opens it. _Note:_ _(i)_ You can use a different text editor if you like. In gnome Linux, `gedit` works really well too. _(ii)_ `nano` (or `gedit`) create text files. It doesn't matter what the file extension is (or if there is one) | ### b) How to delete files and directories... #### _Remember that deleting is forever. There is NO going back_ -* **`rm ./filename`** --> deletes a file called `filename` from the current directory -* **`rmdir ./dirname`** --> deletes the directory `dirname` from the current directory. _Note:_ `dirname` must be empty for `rmdir` to run. + +| Command | Definition | +|-------------------|------------------------------------------------------------------------------------------------------------------| +| `rm ./filename` | deletes a file called `filename` from the current directory | +| `rmdir ./dirname` | deletes the directory `dirname` from the current directory. _Note:_ `dirname` must be empty for `rmdir` to run. | ### c) How to copy and rename files and directories... -* **`mv tmp/filename .`** --> moves the file `filename` from the directory `tmp` to the current directory. _Note:_ _(i)_ the original `filename` in `tmp` is deleted. _(ii)_ `mv` can also be used to rename files (e.g., `mv filename newname` -* **`cp tmp/filename .`** --> copies the file `filename` from the directory `tmp` to the current directory. _Note:_ _(i)_ the original file is still there + +| Command | Definition | +|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `mv tmp/filename .` | moves the file `filename` from the directory `tmp` to the current directory. _Note:_ _(i)_ the original `filename` in `tmp` is deleted. _(ii)_ `mv` can also be used to rename files (e.g., `mv filename newname` | +| `cp tmp/filename .` | copies the file `filename` from the directory `tmp` to the current directory. _Note:_ _(i)_ the original file is still there | ## 3. Pipes and Filters ### a) How to use wildcards to match filenames... Wildcards are a shell feature that makes the command line much more powerful than any GUI file managers. +Wildcards are particularly useful when you are looking for directories, files, or file content that can +vary along a given dimension. These wildcards can be used with any command that accepts file names or +text strings as arguments. - -** Table of commonly used wildcards ** +#### Table of commonly used wildcards | Wildcard | Matches | |------------------------|------------------------------------------------| @@ -48,11 +57,22 @@ Wildcards are a shell feature that makes the command line much more powerful tha | `[!a-e]` | any character that is not in the given range | | `{software,carpentry}` | exactly one entire word from the options given | +See the cheatsheet on regular expressions for more "wildcard" shortcuts. + +### b) How to redirect to a file and get input from a file ... + +#### Definitions: +* **stdout**: +* **stdin**: +* **stderr**: +| Command | Description | +|---------|-------------| +| `>` | +| `>>` | +| `<` | +| `<<` | -### b) That wildcards are expanded by the shell before commands are run... -### c) How to redirect a command's output to a file... -### d) How to redirect a command's input from a file... ### e) How to use the output of one command as the input to another with a pipe... ### f) That combining single-purpose filters with pipes is the most productive way to use the shell... ### g) That if a program conforms to Unix conventions, it can easily be combined with others...