You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-15Lines changed: 17 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,7 +211,7 @@ nano sample/my_file.txt
211
211
> At the bottom of the `nano` screen, you will find a list of keyboard shortcuts to help you with common tasks. Most importantly, press `Ctrl+O` to save (write out) the file, and press `Ctrl+X` to exit the nano program.
212
212
213
213
> [!TIP]
214
-
> You system may have other text editors installed, such as `vi`, `vim`, etc. They all have their own keyboard shortcuts.
214
+
> You system may have other text editors installed, such as `vi`, `vim`, `emacs` etc. They all have their own keyboard shortcuts.
215
215
216
216
> [!TIP]
217
217
> To see if a command or program is available on your system, run:
@@ -271,17 +271,19 @@ For example:
271
271
cat shakespeare.txt
272
272
```
273
273
274
-
We just "read" the complete works of Shakespeare in 5 seconds, but that's not helpful! Now let's try to read them page by page using the `more` command:
274
+
We just "read" the complete works of Shakespeare in 5 seconds, but that's not helpful! Now let's try to read them page by page using the `more` or `less` command:
275
275
```
276
276
more [/path/to/file]
277
+
less [/path/to/file]
277
278
```
278
279
For example:
279
280
```
280
281
more shakespeare.txt
282
+
less shakespeare.txt
281
283
```
282
284
283
285
> [!TIP]
284
-
> With `more`, you can use the spacebar to **scroll** pages and type in `q` to **quit** the interface.
286
+
> With `more` or `less`, you can use the spacebar to **scroll** pages and type in `q` to **quit** the interface.
285
287
286
288
For large tabular data files, we might just want to look at the **first a few rows** to get a sense of the data. We can use the `head` command to achieve that:
The **single chevron** `>` replaces the existing content of the target file with the output of the command. This can make sense in a lot of situations, but you have to be extra careful not overwriting any file that you don't intend to overwrite. Again, the terminal usually does not ask you for confirmation.
Now that we know what these commands do, let's put them in a file so that we never have to type in such long commands again! You can use `nano`, or your favorite text editors, to create these script files.
396
398
397
399
Let's create a script file called `top_ten`:
398
400
```
399
-
#!/bin/bash
401
+
#!/bin/bash
400
402
401
403
date
402
404
@@ -410,22 +412,22 @@ head results-${file}
410
412
date
411
413
```
412
414
413
-
Additionally, let's create another script file called `combine_data`
415
+
Additionally, let's create another script file called `select_combine`
echo "All set. $COUNTER files were processed. File results-covid.csv was generated."
429
431
430
432
date
431
433
```
@@ -440,7 +442,7 @@ The best way to explain that is to take a look at the output of the `ls -l` comm
440
442
441
443
```
442
444
ls -l top_ten
443
-
ls -l combine_data
445
+
ls -l select_combine
444
446
```
445
447

446
448
@@ -453,8 +455,8 @@ You will typically find a 10-character string at the beginning of each line, whi
453
455
You can see that our newly created files are not executable by anyone! Let's fix that. You will need the **change mode** command `chmod`:
454
456
```
455
457
chmod +x top_ten # make it generally executable
456
-
chmod u+x combine_data # Only make it executable for the owner
457
-
chmod g+x combine_data # Only make it executable for the group
458
+
chmod u+x select_combine # Only make it executable for the owner
459
+
chmod g+x select_combine # Only make it executable for the group
458
460
```
459
461
460
462
This is fine, but if you read the instructions of some programs, you will often encounter `chmod` used with numbers, which are known as the **Octal Representation of File Permissions**:
OK, now that we have made our scripts executable, we can run them!
482
484
```
483
485
./top_ten
484
-
./combine_data
486
+
./select_combine
485
487
```
486
488
487
489
You will notice that we prefix the commands with `./`, which instructs the shell to look for the program in the present working directory. This is the convention and best practice for running your own scripts, because if you don't specificy a specific path, the shell will first look for a command at the system level by that name. It is not only inefficient, but also could be dangerous. There are thousands of system commands, and if one of them happens to have the same name as your script, you could be running that command instead.
0 commit comments