compsci-missing_semester_2020/_subsections/lesson-05.org
2025-07-28 06:10:28 +03:00

291 lines
7.6 KiB
Org Mode
Executable file

#+title: Lesson 05 | Command line Environment
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../_share/media/css/missing-semester.css" />
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../_share/media/css/org-media-sass/collapsible.css" />
#+HTML_HEAD: <script src="../_share/media/js/collapsible.js"></script>
#+OPTIONS: H:6
* Links
#+attr_html: :class links
- [[../toc.org][TOC | Missing Semester]]
- [[https://www.youtube.com/playlist?list=PLyzOVJj3bHQuloKGG59rS43e29ro7I57J][Playlist: Missing Semester]]
- [[https://www.youtube.com/redirect?event=video_description&redir_token=QUFFLUhqbVVJc2RzZ25nMmlrVW5zVGRsTS1fX2ladmRPQXxBQ3Jtc0ttWjQ5Ujcyd19TekNncTZGNEp1eDc3RWhzTzhvMW9oSTFoUl9JbGt1Mi0yU3FLc00wVUx1UXNJdFQxTjBjMWphdUZxNnU1WUYzTmFqd3RRemNLUDBJMlZkV3B0SnB4RVhpaUhvWWtnc1RISW1WVzdYWQ&q=https%3A%2F%2Fmissing.csail.mit.edu%2F2020%2Fcommand-line%2F&v=e8BO_dYxk5c][class notes]]
- Curr: https://youtu.be/e8BO_dYxk5c?si=ttNryjIiOS0BxBqD&t=2542
*** timestamps
:PROPERTIES:
:CUSTOM_ID: timestamp
:END:
#+attr_html: :class playlist
+ [[https://youtu.be/e8BO_dYxk5c?si=A-imhHunQCtp_-Oz][00:00 - introduction]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=138s][02:18 - Job Control]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=227s][03:47 - Signal Interrupts]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=360s][06:00 - Python Program]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=672s][11:12 - The Kill Command]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=881s][14:41 - Terminal Multiplexer]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=1112s][18:32 - The Key Bindings]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=1536s][25:00 - Dot Files]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=1799s][29:59 - Context Based Configuration File]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=2004s][33:24 - Terminal Emulator]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=2196s][36:36 - Aliases]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=2286s][38:06 - Common Folder Structure]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=2344s][39:04 - Symlinks]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=2552s][42:32 - ssh]] *current*
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=2715s][45:15 - ssh keys]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=3057s][50:57 - ssh config]]
+ [[https://www.youtube.com/watch?v=e8BO_dYxk5c&t=3231s][53:51 - changing the prefix]]
* notes
** topics
- job control
- terminal multiplexers
- dot files / how to configure
- work with remote machines
** job control
*** sleep
- puts process to sleep for a specified amount of time
- exit by typing Ctrl-C
*** Ctrl-C
- sends SIGINT - signal interrupt
- man signal will show the list of signals
** signals
- SIGQUIT :: signal sent when we want to quit
- SIGTERM :: similar to quit but not in term
- SIGHUP :: when we have processes running but still want to close
*** pausing
- SIGSTOP :: pause execution of program
- SIGCONT :: continue program
*** python library
- use import signal
#+BEGIN_SRC python
import signal
def handler(signum, frame):
printf("signal received")
signal.signal(signal.SIGINT, handler)
#+END_SRC
- the above would catch a Ctrl-C and run it through handler
- you use this by catching a Ctrl-C and running any saves or cleanup before exiting
** nohup and jobs
- allows for a process to continue livign when the terminal is killed
*** example
- sleep put the process to sleep
- '&' puts the process in the background
- wont take over the process
#+BEGIN_SRC bash
nohup sleep 2000 & python somprog.py
#+END_SRC
*** jobs
- ~jobs~
will show the suspended and running processes in background
- how to restart a suspended process
- type 'jobs' to see what there is in this terminal
- the find the jobs number, ie [1] or [2]
- use the 'bg' command
#+BEGIN_SRC bash
bg %1
#+END_src
** kill command
- allows you to send any kind of signal to a job
- e.g. "stop" will suspend but not close the job
*** some commands
- HUP :: Hang Up
- STOP :: suspend
- KILL :: kill it no matter what
** Terminal Multiplexer
*** overview
- tmux
- lets you create workspaces that you can work in
- rearrange the environment
- have different settings
*** core concepts
- hierarchy
- sessions
- windows
- panes
** dot files
*** alias
- remap a source series of characters to a longer series
- alias takes a single argument, ie, do not use spaces
- to show what an alias refers to pass the alias to the alias command
- e.g.
#+begin_src bash
~/somedirectory >>> alias myaliasedcommand
myaliasedcommand='ls -lah'
#+end_src
**** examples
- make an alias "ll" for a list command with flags
#+begin_src bash
alias ll="ls -lah"
#+end_src
- make an alias for git status
#+begin_src bash
alias gs="git status"
#+end_src
- alias to prompt for an override
#+begin_src bash
alias mv="mv -i"
#+end_src
*** text based configuration 'dot files'
- called 'dot files' because they start with a dot
- .bashrc
- must be in the home directory
- PS1
- prompt variable for your prompt
- you can set it in the .bashrc file
- ~PS1=" >> "~
- .vimrc
- vim configuration file
** tmux
- run a session, detach and get back to it later
*** link
- [[https://tmuxcheatsheet.com][cheat sheet]]
- [[https://www.youtube.com/watch?v=nTqu6w2wc68][network chuck tutorial]]
*** prefix key
Ctl-B
*** userful commands
**** detach / attach
- Ctl-B , D -> detach
- tmux a -> reattach
**** reattach to most recent session
- tmux a
**** attach to a particular session
- list the tmux session
- note the index number or name
- attach to that index -t (target)
~tmux a -t [INDEX]
**** kill
***** kill a session
tmux kill-session -t [INDEX]
***** kill session from list windows
- go into list windows C-b w
- highlight the one you want dead
- C-b x, it will ask for confirmation
***** kill ALL sessions
tmux kill-server
***** kill a pane
C-b x
***** kill an entire window
C-b &
**** tmux names session
-
~tmux new -s name~
**** list session
- tmux ls
*** 3 layers
**** layer 1 -> sessions
- when you hit tmux you start a new tmux session
**** layer 2 -> window
- when you create a new session, you automatically create an initial window
- C-b c :: create a new window in addition to the existing ones
- all windows will be listed in the display line at the bottom
- the * indicates the current
- C-b n :: move through your windows
- C-b < :: rename window
- C-b w :: list all sessions and windows
- you can walk through the list using arrow keys
- enter to switch
***** kill session
- go into list windows C-b w
- highlight the one you want dead
- C-b x, it will ask for confirmation
**** layer 3 -> panes
- panes exist in windows
- add horizontal pane :: C-b %
- add vertical pane :: C-b "
- switch panes :: C-b [arrow]
- show pane index :: C-b q
- switch to pane index :: C-b q [index]
- change pane size :: C-b [hold Ctl] [arrow]
***** preselected pay layout
- C-b Alt-1-5
***
** terminal emulator - alacritty
- very fast
- useful for heavy displays like neoviim
- vm mode is good for reloading
*** hint system
- pattern recognition of terminal output based on regex
- execute commands on those patterns
**** e.g.
- url will be opened in browser
**** custom actions
- shows hints overlay over something recongized
- for files or other customized action
*** themes
- black theme
*** copy mode / vim
- treat terminal output as a vim buffer
- doesn't support all, but a lot
** aliases
you can find good alias lists online
** common folder structures
- use symlinks to store all your dotfiles in one directory
- ~ln -s [path-to-orig] [path-to-link-location]~
#+begin_src text
~
├─ .bashrc
├─ .vimrc
└─ dotfiles
├─ bashrc
└─ vimrc
#+end_src