Skip to content

Commit

Permalink
More notes on CLI, circuits
Browse files Browse the repository at this point in the history
- Streams, redirection, pipes, jobs
- Some parsed circuit notes from ECS 154A
  • Loading branch information
jzkyu committed Oct 15, 2023
1 parent 4411d97 commit 0a5e6ae
Show file tree
Hide file tree
Showing 26 changed files with 337 additions and 6 deletions.
Binary file added docs/Public/Media/FullAdder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Public/Media/FullAdderLessHardware.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Public/Media/HalfAdder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Public/Media/Multiplication.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Public/Media/Mux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/Public/Software/Computer Architecture/gate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A *gate* is the building block of a computer, performing basic logical functions. [^1]

They have multiple inputs, and produce one output.

[^1]: https://www.techtarget.com/whatis/definition/logic-gate-AND-OR-XOR-NOT-NAND-NOR-and-XNOR#:~:text=A%20logic%20gate%20is%20a,of%20logic%20gates%20in%20them.
7 changes: 7 additions & 0 deletions docs/Public/Software/Computer Architecture/multiplexer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
A *multiplexer* selects one of its [[data]] ports to forward to the output based on the selection signal.

It behaves like a switch statement in programming.

![[Mux.png]]

In general, a *multiplexer* has $2^n$ data inputs and requires $n$ select bits to choose which one will be the output. Larger *multiplexers* can be constructed with [[gate]] and [[tree]] of other *multiplexers*.
5 changes: 5 additions & 0 deletions docs/Public/Software/Networks/SSH.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

*SSH* is often used to "login" and perform operations on remote computers, but can also be used for transferring data. [^1]

You can run a [[command]] on remote machines and [[pipe]] the result:
```bash
ssh [email protected] ls | grep Downloads
```

[^1]: https://www.ucl.ac.uk/isd/what-ssh-and-how-do-i-use-it
52 changes: 51 additions & 1 deletion docs/Public/Software/Operating Systems/Bash cheat sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,54 @@ cp <flags> <sourcePath(s)> <destinationPath>
rm <flags> <filePath(s)>
```
- Remove each specified file permanently
- Does not remove directories by default
- Does not remove directories by default
```bash
alias <aliasName>='<commandToRun>'
```
- Substitutes the alias name with the command to be run
- Create shortcuts for tedious commands
- Extend the default behavior of commands
```bash
alias rm='rm -i' # confirm to delete file
alias rm='mv -t -/.tash' # move file to a trash directory
alias cp='cp -b' # make backup of destinationFile
alias mv='mv -u' # move only if sourceFile is newer
alias hello="echo 'cow power'"
```

```bash
cat <flags> <file>
less <flags> <file>
```
- Print contents of file to screen; concatenate
- `less` outputs a page at a time, to scroll through
- Can search through file using the `/<word>`
```bash
head <flags> <file>
```
- Shows the first 10 lines of a file
- Use `-n <number of lines>` to print certain number of lines from file
```bash
tail <flags> <file>
```
- Shows the last 10 lines of a file
```bash
nano <flags> <file>
```
- Opens simple [[CLI]] text editor
```bash
vim <flags> <file>
```
- Another text editor
```bash
man <command>
man mkdir
man stdio
```
- System reference manuals
- Contains details of all command behavior and flags
- Documentation of c libraries
```bash
tldr <flags> <command>
```
- Lists the typical uses of a command
2 changes: 1 addition & 1 deletion docs/Public/Software/Operating Systems/Bash.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*See:* [Advanced Bash-Scripting Guide](https://tldp.org/LDP/abs/html/)
*See:* [Advanced Bash-Scripting Guide](https://tldp.org/LDP/abs/html/), [[Bash cheat sheet]]

*Bash* is a [[shell]] that is widely used in [[Linux]] and [[MacOS]] as the default shell. [^1]

Expand Down
28 changes: 27 additions & 1 deletion docs/Public/Software/Operating Systems/command.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
A *command* is a request to perform an operation or run a program.

You can add a [[flag]] which affect how a *command* can work.
You can add a [[flag]] which affect how a *command* can work.

`;`:
- Execute *commands* in series
```bash
echo -n "hello " ; echo "world"
hello world
```

`&&`:
- Conditionally on success
```bash
cat / && echo "world"
cat: /: Is a directory
cd ~/slides/ && du -sh Makefile
4.0K Makefile
```

`||`:
- Conditionally on failure
```bash
cat / || echo "Cat failed"
cat /: Is a directory
Cat failed
echo -n "hello" || echo "world"
hello
```
14 changes: 14 additions & 0 deletions docs/Public/Software/Operating Systems/exit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
An *exit* occurs when the command finishes.

A `0` indicates success. Any other value indicates error.

```bash
echo "Hello" > /dev/null
echo $?
0

cat missing.txt
cat: missing.txt: No such file or directory
echo $?
1
```
2 changes: 1 addition & 1 deletion docs/Public/Software/Operating Systems/file system.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
A *file system* of an [[operating system]] generally has a [[tree]] data structure for [[file]] which branches from the [[root]] to different directories.
A *file system* of an [[operating system]] generally has a [[tree]] data structure for [[file]] which branches from the [[[knowledge-base/docs/Public/Software/Theory/root|root]] to different directories.
10 changes: 9 additions & 1 deletion docs/Public/Software/Operating Systems/flag.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
A *flag* can be added to a command to affect how it works.

Flags are combinational and the order does not matter.
Flags are combinational and the order does not matter.

`-h`: Help

`-V`: Version

`-v`, `-vv`, `-vvv`, `--quiet`: Configurable verbosity level

`-r`: Recursive
Empty file.
13 changes: 13 additions & 0 deletions docs/Public/Software/Operating Systems/kernel.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@ The *kernel* is a computer program that is at the core of a computer's [[operati

The *kernel* interacts with the [[shell]] and other programs, as well as the computer's [[hardware]], including the [[processor]], [[memory]], and disk drives. [^1]

Kernel parameters can be accessed through a pseudo [[file system]] `/sys`
```bash
cat /sys/class/input/mouse0/device/name
Logitech USB Optical Mouse
cat /sys/class/hwmon/hwmon3/temp1_crit
120000
cat /sys/class/leds/input2::scrolllock/brightness
0
```
- Some system variables can be changed on the fly
```bash
sudo bash -c "echo 1 > /sys/class/leds/input2::scrollock/brightness"
```
[^1]: https://www.linfo.org/kernel.html
27 changes: 27 additions & 0 deletions docs/Public/Software/Operating Systems/path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
A *path* is a special variable used to find the executable of a program. The [[shell]] searches `$PATH` when you enter a [[command]].

```bash
which ls
/usr/bin/ls
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/cuda-10.1/bin:/usr/lib/jvm/default/bin ...
echo $PATH | sed 's/:/\n/g'
/usr/local/sbin
/usr/local/bin
/usr/bin
/opt/cuda-10.1/bin
/usr/lib/jvm/default/bin
```
- You can run a program without searching for its path
```bash
./hello
Hello World!
```

```bash
hello
bash: hello: command not found
sudo mv hello/usr/local/bin
hello
Hello World!
```
10 changes: 10 additions & 0 deletions docs/Public/Software/Operating Systems/pipe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
A *pipe* is used to combine two or more commands. It will take the output of a [[command]] and use that as the input for the next command. [^1]

Using the *pipe* '|' character:
```bash
ls -l / | tail -n3
```

You can chain *pipes* together.

[^1]: https://www.redhat.com/sysadmin/pipes-command-line-linux
64 changes: 64 additions & 0 deletions docs/Public/Software/Operating Systems/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,68 @@ A *process* is a program or [[command]] that is actually running on the computer

The [[operating system]] can run many different processes at the same time. [^1]

*Process* commands on the [[CLI]]:

`Ctrl+C`:
- Stops a process
```bash
sleep 60
^C
```

`Ctrl+Z`:
- Pause a process
```bash
sleep 5
^Z
[1]+ Stopped sleep 5
echo "Hello"
Hello
```

`fg`, `bg`:
- Resume in either foreground or background
```bash
fg
sleep 5
```

```bash
bg
[1]+ sleep 5 &
echo "What now?"
What now?
[1]+ Done sleep 5
```

`&`:
- Start a process in the background
```bash
cat /dev/random > /dev/null &
```

`jobs`:
- Lists all jobs (processes)
```bash
jobs
[1]- Stopped cat /dev/random > /dev/null
[2]+ Stopped sleep 10
```

`kill`:
- Terminate jobs (processes)
```bash
kill %1
[1]+ Terminated cat /dev/random > /dev/null
```

- Jobs are tied to the [[terminal]] session
- Exiting terminal kills stopped and backgrounded jobs

- Protect background job from terminal exit:
```bash
nohup sleep 10 & // "no hang up" for a new job
disown %1 // For a job already running
```

[^1]: https://www.ibm.com/docs/pt-br/aix/7.1?topic=administration-commands-processes
21 changes: 21 additions & 0 deletions docs/Public/Software/Operating Systems/redirection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
*See: * [[stream]]

A *redirection* is a way to change the standard input / output of the [[CLI]] to point to and from files. [^1]
You can redirect `stdout` to a file like this:
```bash
echo "Hello World!" > hello.txt
cat hello.txt
```

Redirect `stdin`:
```bash
cat < hello.txt
```

Append `stdout` to a file:
```bash
cat < hello.text >> hello_copy.txt
```


[^1]: https://www.guru99.com/linux-redirection.html
9 changes: 9 additions & 0 deletions docs/Public/Software/Operating Systems/root.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*Root* is a user account for administrative purposes, and typically has the highest access rights on the system. [^1]

You can use `sudo` to perform actions as *root*.
- Short for "super user do"
- Actions run as root can damage your system

Some things do require *root* privileges, if they change any files in the *root*.

[^1]: https://www.ssh.com/academy/pam/root-user-account#:~:text=Root%20is%20the%20superuser%20account,account%2C%20regardless%20of%20the%20name.
62 changes: 62 additions & 0 deletions docs/Public/Software/Operating Systems/stream cheat sheet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
*See:* [[stream]]
`head`:
- Sends the first `n` lines of its input to its output
```bash
head -n3
```

`tail`:
- Sends the last `n` lines of its input to its output
```bash
tail -n3
```

```bash
ls -l / > temp.txt
tail -n3 < temp.txt
```

`grep`:
- Searches the input stream for a string
- Outputs every line that contains the string
```bash
history | grep tail
```

`cut`:
- Removes sections from each line of the input
- Useful when filtering columns from input
```bash
cat foo.txt
A,B,C,D
A,B,C,D
B,B,C,D
D,C,B,A
cat foo.txt | cut -d "," -f1,4
A,D
B,D
D,A
```

`sort`:
- Sorts the input and sends it to `stdout`
- Defaults to alphanumeric sort, but it has many sorting options

`uniq`:
- Outputs the unique lines in the input
- Only detects repeated lines if they are adjacent
- Input needs to be sorted first
```bash
sort foo.txt | uniq // Display each line once
sort foo.txt | uniq -u // Display only unique lines
sort foo.txt | uniq -d // Display only duplicated lines
sort foo.txt | uniq -c // Display frequency of each line
```

`tee`:
- Read from standard input and write to standard output and files
```bash
echo 1 | sudo tee /sys/class/leds/input2::scrolllock/brightness
```


7 changes: 7 additions & 0 deletions docs/Public/Software/Operating Systems/stream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*See:* [[stream cheat sheet]]

A *stream* refers to a collection of text.

There are generally two *streams* in the command line:
- `stdin` for user input (default is keyboard)
- `stdout` for user output (default is display)
3 changes: 3 additions & 0 deletions docs/Public/Software/Operating Systems/text editor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A *text editor* is a program that edits plain text. They are sometimes known as "notepad" software. [^1]

[^1]: https://en.wikipedia.org/wiki/Text_editor
Loading

0 comments on commit 0a5e6ae

Please sign in to comment.