Skip to content

Commit 1419b2c

Browse files
author
Lei Wang
committed
Updated readme.
1 parent c2088da commit 1419b2c

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ nano sample/my_file.txt
211211
> 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.
212212
213213
> [!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.
215215
216216
> [!TIP]
217217
> To see if a command or program is available on your system, run:
@@ -271,17 +271,19 @@ For example:
271271
cat shakespeare.txt
272272
```
273273
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:
275275
```
276276
more [/path/to/file]
277+
less [/path/to/file]
277278
```
278279
For example:
279280
```
280281
more shakespeare.txt
282+
less shakespeare.txt
281283
```
282284
283285
> [!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.
285287
286288
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:
287289
```
@@ -353,7 +355,7 @@ command_name [options] [parameters] >> /path/to/file
353355
For example:
354356
```
355357
echo 'Hello world!' > hello.txt
356-
echo ' So happy to be here!' >> hello.txt
358+
echo 'So happy to be here!' >> hello.txt
357359
```
358360
359361
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.
@@ -389,14 +391,14 @@ cat shakespeare.txt | tr -sc [:alpha:] '\n' | sort -f | uniq -ci | sort -bnfr >
389391
```
390392
391393
```
392-
head -n 101 covid.csv | tail -n 100 | sort -r | cut -d , -f 2,3,4,5 > results-covid.txt
394+
tail -n +2 covid.csv | sort -r | cut -d , -f 2,3,4,5 > results-covid.txt
393395
```
394396
395397
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.
396398
397399
Let's create a script file called `top_ten`:
398400
```
399-
#! /bin/bash
401+
#!/bin/bash
400402

401403
date
402404

@@ -410,22 +412,22 @@ head results-${file}
410412
date
411413
```
412414
413-
Additionally, let's create another script file called `combine_data`
415+
Additionally, let's create another script file called `select_combine`
414416
```
415-
#! /bin/bash
417+
#!/bin/bash
416418

417419
date
418420

419421
COUNTER=0
420422

421423
for datafile in covid*.csv
422424
do
423-
echo "Adding $datafile …"
424-
tail -n +2 $datafile | sort -r | cut -d , -f 2,3,4,5 >> combined-covid.csv
425+
echo "Selecting columns from $datafile and adding them …"
426+
tail -n +2 $datafile | sort -r | cut -d , -f 2,3,4,5 >> results-covid.csv
425427
COUNTER=$((COUNTER + 1))
426428
done
427429

428-
echo "All set. $COUNTER files were added."
430+
echo "All set. $COUNTER files were processed. File results-covid.csv was generated."
429431

430432
date
431433
```
@@ -440,7 +442,7 @@ The best way to explain that is to take a look at the output of the `ls -l` comm
440442
441443
```
442444
ls -l top_ten
443-
ls -l combine_data
445+
ls -l select_combine
444446
```
445447
![Permissions](./images/permissions.jpg)
446448
@@ -453,8 +455,8 @@ You will typically find a 10-character string at the beginning of each line, whi
453455
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`:
454456
```
455457
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
458460
```
459461
460462
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**:
@@ -481,7 +483,7 @@ sudo command_name [options] [parameters]
481483
OK, now that we have made our scripts executable, we can run them!
482484
```
483485
./top_ten
484-
./combine_data
486+
./select_combine
485487
```
486488
487489
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

Comments
 (0)