# terminal

## Open a terminal from another (e.g. VSCode) terminal

```bash
open -a terminal .
```

## Add to path on Mac

```bash
vim /etc/paths
```

## Using pipe and grep

```bash
pip3 freeze | grep Xlsx
```

## Open current directory in finder

```bash
open .
```

## Find and kill process on a port

```bash
lsof -i tcp:3000
kill [PID]
```

## Recursively remove `node_modules`

```bash
find . -name "node_modules" -exec rm -rf '{}' +
```

## Location of a command in PATH

The following will return something along the lines of `hie is /Users/username/.local/bin/hie`:

```bash
type -a hie
```

## Common commands

* `clear` - clear the terminal
* `pwd` - print working directory
* `mkdir` - make directory
* `touch` - create a file (e.g. touch example.txt)
* `cp` - copy (e.g. cp file.txt target\_directory)
* `mv` - move (e.g. mv file.txt target\_directory), can also rename a file (e.g. mv old\_file\_name.txt new\_file\_name.txt)
* `rm` - remove (e.g. rm file.txt), can also remove files recursively (e.g. rm directory\_name)
* `echo` - send to stdout
* `cat` - read content of a file
* `alias` - set aliases (e.g. alias pd="pwd" means pd can be used interchangably with pwd)
* `export` - set environment variables!
* `env` - return list of environment variables
* `>` - redirect stdout to a file (e.g. echo "Hello" > hello.txt)
* `>>` - append stdout to a file
* `<` - redirct stdin to a command (e.g. cat < file.txt)
* `|` - pipe stdout of LHS as stdin to RHS
* `wc` - word count (of a text file)
* `uniq` - unique the contents of a file (on a line-wise basis?)
* `grep` - global regular expression print (-i adds case insensitivity, -R recursive, e.g. within directory)
* `sed` - 'streams editor', can be used for find and replace
* `nano` - text editor
* `source` - source \~/.bash\_profile makes all aliases available in the current session
* `history` - command history

## Environment settings

* Stored in:

```bash
~/.bash_profile
```

(where \~ is an alias for $HOME and . represents a hidden file)

## How cmd line works

* Most commands are stored in `/bin`
* `/bin` is a directory on the path (...and hence is available in a terminal session)
* Hence you can see all commands using: `cd /bin`, `ls`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.robmurtagh.com/terminal/terminal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
