Skip to content

Commit 9bd548e

Browse files
authored
Merge pull request #153 from FAIR2-for-research-software/ns-rse/141-bash-basics
2 parents d8fdc0d + 3548daa commit 9bd548e

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

episodes/introduction.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,46 @@ cd ~/te <Tab>
191191
tests/ tmp/
192192
```
193193

194+
#### Redirection
195+
196+
This course uses the redirection pipes `>` to "pipe" what is on the left of the symbol into the file give on the
197+
right. A single `>` will over-write any contents in the file if it already exists. If you want to append something to a
198+
file you can use `>>` instead.
199+
194200
#### History
195201

196202
Bash keeps a record of the commands you use in its `history`. You can view _all_ your history by simply typing
197203
`history`.
198204

199205
```bash
200206
history
201-
207+
...
202208
cd work
203209
mkdir git
204210
git clone git@github.com:ns-rse/python-maths
205211
```
206212

213+
You can recall previous commands using the `Ctrl + p` or the Up arrow, each press takes you to the `p`revious command in
214+
the history. You can move forwards to the `n`ext command using `Ctrl + n` or the Down arrow. When you get to the command
215+
you want simply hit `Return` to execute it.
216+
217+
This is really useful but what if there is a command you know you've used at some point in the past but it wasn't
218+
recently? It could take a long time going back through the history one command at a time. Fortunately you can search
219+
your history for a command using `Ctrl + r` to carry out a "reverse search" on the term you enter. Each subsequent press
220+
of `Ctrl + r` will go the previous match.
221+
222+
::::::::::::::::::::::::::::::::::::: callout
223+
224+
## Readline Library
225+
226+
There are a lot of useful key chords that have evolved over the years which make navigating on the command line easier
227+
and faster. They have been collected into the [Readline library][readline].
228+
229+
These are available not just in Bash but many other command line interfaces (CLI) and learning them will make you
230+
quicker when working at the command line. A useful [cheatsheet][readlinecheat] is available.
231+
232+
::::::::::::::::::::::::::::::::::::::::::::::::
233+
207234
### Nano
208235

209236
[Nano][nano] is a basic terminal editor, you open files by calling `nano <path/to/filename>`, there is a useful [nano
@@ -231,7 +258,7 @@ When done editing you need to exit and return to the command line, you do this w
231258

232259
::::::::::::::::::::::::::::::::::::: callout
233260

234-
#### Useful alias
261+
## Useful alias
235262

236263
You may want to set the following alias in your `~/.bashrc` file, it sets various options. You can then `source
237264
~/.bashrc` to
@@ -697,6 +724,8 @@ the most well known but there are many others including [BitBucket][bitbucket],
697724
[pytest]: https://docs.pytest.org/
698725
[rustGithub]: https://github.com/rust-lang/rust
699726
[r]: https://www.r-project.org/
727+
[readline]: https://tiswww.cwru.edu/php/chet/readline/rltop.html
728+
[readlinecheat]: https://readline.kablamo.org/emacs.html
700729
[snapcast]: https://mjaggard.github.io/snapcast/
701730
[sourcehut]: https://sourcehut.org/
702731
[swCarpentryGit]: https://swcarpentry.github.io/git-novice/

0 commit comments

Comments
 (0)