# Terminal Resources
## Terminal Emulator
First, you need a terminal emulator. On a unix-like system (e.g. mac or any flavor of linux), you probably have one installed already that works fine. You could install a different one if you want though, such as [kitty](https://sw.kovidgoyal.net/kitty/) or (if you're on a mac) [iterm2](https://iterm2.com/). If you use kitty, I've found that it is helpful to include the line:
```
alias ks="kitty +kitten ssh"
```
in the file `~/.bash_profile`. Then instead of `ssh`, you can use `ks`. This fixes some weird issues (honestly I've forgotten what the issue was - I think it might have been to do with colors or something).
Personally, I've used iterm2 for many years, but frankly I have no reason to believe that it makes much of a difference.
If you're on windows, I believe the [windows terminal](https://github.com/microsoft/terminal) app is good - note that I think modern windows machines may come with some terminal pre-installed, which may or may not be the same as this app (I'm not totally sure). I've also heard that [MobaXterm](https://mobaxterm.mobatek.net/) is good.
## Connecting
To do work on the SCC, you should first run the command `ssh <username>@scc1.bu.edu`. This will prompt you for a password. Then, you will be connected to a machine on the SCC.
## Command-line shortcuts
There are a bunch of shortcuts available in most terminal emulators. Two particlurly useful ones are `ctrl-a` and `ctrl-e`, which take you to the beginning and end of a line. Also `ctrl-k` will delete everything after the cursor in a line. These shortcuts also work in the emacs text editor, and in many other places too (try it in your browser's address bar!)
Most emulators support some notion of "tabs" using `ctrl-T` or `Cmd-T` on mac. I no longer know the shortcut for cycling through tabs on non-mac. On Mac it is usually `cmd-{` or `cmd-}`.
## History
* Press "up arrow" and "downarrow" to cycle through a history of commands you have entered in the past.
* Do `ctrl-r` and then start typing to *search* through the history of previous commands. This one is *extremely* useful.
## Concepts
* path: a path is just a location for a file, like `/usr2/faculty/cutkosky/text_file.txt`. In window systems, paths usually start with a "drive", like `C:program_files\firefox.exe`. Note that windows uses `\` instead of `/` to separate directories.
* A path that starts with `/` is called an "absolute path". The other kind of path is a relative path. To understand relative paths, you need to know what a working directory is.
* Working directories and relative paths: There is alway some directory that is your "working directory". The command `pwd` will print out this directory. Any path that does NOT start with `/` is called a "relative path". A relative path can be converted into an absolute path by appending it to the working directory. For example, if the working directory is `/usr2/faculty/cutkosky`, then the relative path `sample.txt` and the absolute path `/usr2/faculty/cutkosky/sample.txt` refer to the same file.
* man pages: if you don't know what a command does (say `pwd`), you can type `man pwd` to see a text file of documentation for the command. This is called a "man page", (man is short for manual).
* wildcards: you can use `*` to indicate "placeholders" in file names. For example: `rm *.txt` will delete ALL files with the ".txt" extension in a directory.
## Useful commands
* `ls`: list contents of directory. You can provide options: `ls -l` will list contents with more information (e.g. file sizes) and will also show "hidden" files. A file is "hidden" if its name starts with a `.`. You can provide a path argument to `ls`, in which case
* `cd`: change working directory.
* `pwd`: print the entire absolute path of the current working directory.
* `ps`: list processes.
* `jobs`: list all processes directly launched by the current shell.
* `kill <PID>`: equivalent to hitting `ctrl-C` for the process with ID `<PID>`. You can find PIDs via the `ps` command. `jobs` gives a Job Id instead, and you can use this with `kill %<JOB ID>` (notice the `%`). Some processes will be recalcitrant and not die with this command. If you are sure that it not going to cause a serious problem if the process immediately gets deleted, you can do `kill -9 <PID>`. This is kind of like "super-kill": the OS will directly kill the process without giving it a chance to clean up resources.
* `echo`: prints its arguments.
* `head <filename>`: print first few lines of a file.
* `tail <filename>`: print last few lines of a file.
* `cat <filename>`: print entire contents of a file.
* `grep`: search for some pattern or string in a file. If no file is provided, will search through stdin instead.
grep Examples:
```
grep Error: logs.txt # will print all lines of logs.txt that contain "Error:"
cat logs.txt | grep Error: # equivalent to above
```
* `less`: kind of an "interactive cat" for large files: allows you to scroll through at your own pace.
* `sort`: sorts lines in a file.
* `shuf`: shuffles lines in a file.
* `pushd`/`popd`
* `cut`: removes columns from csv files
## Useful techniques
* Tab-completion: usually if you partially type out a path, you can hit "tab" to complete it to the longest matching file/directory name. For long paths, this can save a lot of time.
* `ctrl-C`: usually kills whatever process is running in the terminal. Technically, this sends a `SIGINT` signal to the process. The default behavior when recieving this signal is to exit, but some processes may choose to do something else (for example, text editors usually do not exit).
* Setting up a `~/.bashrc`. In your home directory there is a file `~/.bashrc` (if it is not there, you can go ahead and create it). When you log in to the SCC (or on your personal computer, when you open a terminal), all the commands in this file will get execture. You can use it to load up any commands you always do on startup. For example, mine is:
```
#
# default .bashrc
# 03/31/13
#
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
umask 022
# disable coredumps by default
ulimit -c 0
# User specific aliases and functions
alias rm='rm -i'
# Added by Ashok on 2023-05-19 to make helix editor work
module load gcc
# Created by `pipx` on 2023-03-15 16:19:56
export PATH="$PATH:/usr2/faculty/cutkosky/.local/bin"
. "$HOME/.cargo/env"
# Added by Ashok on 2023-06-14
module load neovim python3/3.10.5
```