Skip to content

Commit

Permalink
fix notes
Browse files Browse the repository at this point in the history
  • Loading branch information
brownsarahm committed Nov 7, 2024
1 parent 5ac20cc commit 71cc2b3
Showing 1 changed file with 6 additions and 217 deletions.
223 changes: 6 additions & 217 deletions notes/2024-11-06.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,225 +138,14 @@ If you prefer to read, see [section 5.2.1- 5.2.6 of nan2tetris book](https://www
To compute the maximum value `max.hack`:
- subtracts the two numbers
- compares the difference to 0
- jumps to different lines based on if it is >0 or not
- assigns the address regiter a value accordingly
- jumps to different lines based on if that difference is >0 or not
- assigns the address register a value accordingly
- copies one of the two values to the new location


```{code-cell} bash
:tags: ["skip-execution"]
python
```

+++{"lesson_part": "main","type":"output"}

```{code-block} console
Python 3.11.4 (main, Jul 5 2023, 09:00:44) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a= 2
>>> b =3
>>> c =max(a,b)
>>> c
3
>>> exit()
```

+++{"lesson_part": "main"}
## File Permissions

First, we will go back to seawulf
```{code-cell} bash
:tags: ["skip-execution"]
ssh -i ~/seawulf [email protected]
```

+++{"lesson_part": "main","type":"output"}

```{code-block} console
Last login: Thu Mar 28 12:33:16 2024 from 172.20.126.231
```

+++{"lesson_part": "main"}
First lets make a file:

```{code-cell} bash
:tags: ["skip-execution"]
[brownsarahm@seawulf ~]$ nano hello.sh
```

+++{"lesson_part": "main","type":"output"}
with a simple script in it
```bash
echo "hello!"
```

+++{"lesson_part": "main"}

If we want to run the file, we can use `bash` directly,
```{code-cell} bash
:tags: ["skip-execution"]
[brownsarahm@seawulf ~]$ bash hello.sh
```

+++{"lesson_part": "main","type":"output"}

```{code-block} console
hello!
```

+++{"lesson_part": "main"}

this is limited relative to calling our script in other ways.


One thing we could do is to run the script using `./`

```{code-cell} bash
:tags: ["skip-execution"]
[brownsarahm@seawulf ~]$ ./hello.sh
```

+++{"lesson_part": "main","type":"output"}

```{code-block} console
-bash: ./hello.sh: Permission denied
```


+++{"lesson_part": "main"}

By default, files have different types of permissions: read, write, and execute for different users that can access them. To view the permissions, we can use the `-l` option of `ls`.




+++{"lesson_part": "main"}

```{code-cell} bash
:tags: ["skip-execution"]
[brownsarahm@seawulf ~]$ ls -la
```

+++{"lesson_part": "main","type":"output"}

```{code-block} console
total 138508
drwx------. 5 brownsarahm spring2022-csc392 4096 Apr 2 13:28 .
drwxr-xr-x. 503 root root 16384 Mar 25 16:47 ..
-rw-r--r--. 1 brownsarahm spring2022-csc392 231 Nov 24 2021 .bashrc
drwxr-xr-x. 2 brownsarahm spring2022-csc392 4096 Mar 28 13:33 compilec
-rw-r--r--. 1 brownsarahm spring2022-csc392 77426528 Jan 16 2018 dmel-all-r6.19.gtf
-rw-r--r--. 1 brownsarahm spring2022-csc392 25056938 Jan 25 2016 gene_association.fb
-rw-r--r--. 1 brownsarahm spring2022-csc392 14 Apr 2 13:28 hello.sh
-rw-r--r--. 1 brownsarahm spring2022-csc392 1625262 Jan 25 2016 SRR307023_1.fastq
-rw-r--r--. 1 brownsarahm spring2022-csc392 1625262 Jan 25 2016 SRR307023_2.fastq
-rw-r--r--. 1 brownsarahm spring2022-csc392 1625376 Jan 25 2016 SRR307024_1.fastq
drwx------. 2 brownsarahm spring2022-csc392 36 Oct 25 22:26 .ssh
-rw-r--r--. 1 brownsarahm spring2022-csc392 658 Apr 7 2020 .zshrc
```

+++{"lesson_part": "main"}

For each file we get 10 characters in the first column that describe the permissions. The 3rd column is the username of the owner, the fourth is the group, then size date revised and the file name.

We are most interested in the 10 character permissions. The fist column indicates if any are directories with a `d` or a `-` for files. We have no directories, but we can create one to see this.



+++{"lesson_part": "main"}

We can see in the bold line, that the first character is a d.

The next nine characters indicate permission to **R**ead, **W**rite, and e**X**ecute a file. With either the letter or a `-` for permissions not granted, they appear in three groups of three, three characters each for owner, group, anyone with access.



+++{"lesson_part": "main"}
we moved the file to make the permissions list shorter
```{code-cell} bash
:tags: ["skip-execution"]
[brownsarahm@seawulf ~]$ mv hello.sh compilec/
[brownsarahm@seawulf ~]$ cd compilec/
[brownsarahm@seawulf compilec]$ ls -l
```

+++{"lesson_part": "main","type":"output"}

```{code-block} console
total 92
-rwxr-xr-x. 1 brownsarahm spring2022-csc392 10032 Mar 28 13:19 demo
-rwxr-xr-x. 1 brownsarahm spring2022-csc392 8360 Mar 28 13:10 demohello
-rwxr-xr-x. 1 brownsarahm spring2022-csc392 8360 Mar 28 13:12 hello
-rw-r--r--. 1 brownsarahm spring2022-csc392 65 Mar 28 13:11 hello.c
-rw-r--r--. 1 brownsarahm spring2022-csc392 16865 Mar 28 12:49 hello.i
-rw-r--r--. 1 brownsarahm spring2022-csc392 1496 Mar 28 12:58 hello.o
-rw-r--r--. 1 brownsarahm spring2022-csc392 433 Mar 28 12:53 hello.s
-rw-r--r--. 1 brownsarahm spring2022-csc392 14 Apr 2 13:28 hello.sh
-rw-r--r--. 1 brownsarahm spring2022-csc392 474 Mar 28 13:14 help.c
-rw-r--r--. 1 brownsarahm spring2022-csc392 3040 Mar 28 13:19 help.o
-rw-r--r--. 1 brownsarahm spring2022-csc392 376 Mar 28 13:17 main.c
-rw-r--r--. 1 brownsarahm spring2022-csc392 3736 Mar 28 13:18 main.o
-rw-r--r--. 1 brownsarahm spring2022-csc392 5 Mar 28 13:33 name.txt
```


here we can compare files we were able to run (the ones we built on this system)
and see they have the `x` permission.

+++{"lesson_part": "main"}

To add execute permission, we can use `chmod`

```{code-cell} bash
:tags: ["skip-execution"]
[brownsarahm@seawulf compilec]$ chmod +x hello.sh
[brownsarahm@seawulf compilec]$ ls -l
```

+++{"lesson_part": "main","type":"output"}

```{code-block} console
total 92
-rwxr-xr-x. 1 brownsarahm spring2022-csc392 10032 Mar 28 13:19 demo
-rwxr-xr-x. 1 brownsarahm spring2022-csc392 8360 Mar 28 13:10 demohello
-rwxr-xr-x. 1 brownsarahm spring2022-csc392 8360 Mar 28 13:12 hello
-rw-r--r--. 1 brownsarahm spring2022-csc392 65 Mar 28 13:11 hello.c
-rw-r--r--. 1 brownsarahm spring2022-csc392 16865 Mar 28 12:49 hello.i
-rw-r--r--. 1 brownsarahm spring2022-csc392 1496 Mar 28 12:58 hello.o
-rw-r--r--. 1 brownsarahm spring2022-csc392 433 Mar 28 12:53 hello.s
-rwxr-xr-x. 1 brownsarahm spring2022-csc392 14 Apr 2 13:28 hello.sh
-rw-r--r--. 1 brownsarahm spring2022-csc392 474 Mar 28 13:14 help.c
-rw-r--r--. 1 brownsarahm spring2022-csc392 3040 Mar 28 13:19 help.o
-rw-r--r--. 1 brownsarahm spring2022-csc392 376 Mar 28 13:17 main.c
-rw-r--r--. 1 brownsarahm spring2022-csc392 3736 Mar 28 13:18 main.o
-rw-r--r--. 1 brownsarahm spring2022-csc392 5 Mar 28 13:33 name.txt
```

now we have x permission on the `hello.sh` and we can run it!


+++{"lesson_part": "main"}

remember to close the server connection

```{code-cell} bash
:tags: ["skip-execution"]
exit
logout
```

+++{"lesson_part": "main","type":"output"}

```{code-block} console
Connection to seawulf.uri.edu closed.
```

+++{"lesson_part": "main"}

```{code-cell} bash
:tags: ["skip-execution"]
```
:::{note}
This program assumes the two values to compare already exist in memory, the program does not set them.
To test it, try changing the values in memory locations 0 and 1.
:::


## Prepare for Next Class
Expand Down

0 comments on commit 71cc2b3

Please sign in to comment.