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: common-content/en/module/tools/individual-shell-tools/index.md
+36-11Lines changed: 36 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,9 +15,34 @@ Through this course, we are going to write lots of programs.
15
15
16
16
But a lot of programs have already been written by other people. It's often quicker and easier to use an existing program than to write a new one.
17
17
18
-
We are going to learn about some commonly used programs. We will learn some common patterns that make them easier to learn them and to combine them.
18
+
Many programs that were written for Unix (the predecessor of Linux) are still used today. Why are these programs still useful today? In part because of the [Unix philosophy](https://en.wikipedia.org/wiki/Unix_philosophy), the way these programs were written: simple, modular and flexible.
19
19
20
-
We run these programs from a terminal. We can either call the programs directly from a terminal, or put instructions to call the programs in a script and run the script.
20
+
-**Simple**: Each tool solves a specific problem, making it easier to understand and learn.
21
+
-**Modular**: We can reuse tools in different ways by combining them.
22
+
-**Flexible**: Pipelines let us build solutions quickly without coding from scratch.
23
+
24
+
We are going to learn about some commonly used programs. We will learn common patterns that make them easier to learn and combine.
25
+
26
+
We run these programs from a terminal. We can either call the programs directly from a terminal, or write the instructions to call the programs in a script and run the script.
27
+
28
+
### Key Concepts
29
+
30
+
**Pipelines**: We can connect programs together so the output of one becomes the input of another using the `|` (pipe) symbol.
31
+
32
+
For example, to find lines containing "error" in all .log files and show how many unique files have them:
33
+
34
+
```console
35
+
% grep -l "error"*.log | wc -l
36
+
3
37
+
```
38
+
39
+
Here, `grep -l "error" *.log` finds all .log files containing "error" and outputs just the filenames, then `wc -l` counts the lines (filenames) to give us the total count.
40
+
41
+
**PATH**: The system searches for programs in directories listed in the PATH environment variable. When you type a command, the shell looks for the program in these directories.
42
+
43
+
**Important**: The current directory (`.`) is not in PATH by default for security reasons. To run a program in the current directory, you must use `./program-name` instead of just `program-name`.
44
+
45
+
**Finding programs**: Use `which <program-name>` to see where a program is located.
21
46
22
47
### Conventions
23
48
@@ -31,24 +56,24 @@ file1 file2
31
56
Here we are saying: At a terminal prompt (signified by the `%`), run the command `ls`.\
32
57
Below the command is the output (`file1 file2`) you should expect to see after you run the command. Sometimes this is the exact output you should expect. Sometimes _example_ outputs are given: these could vary according to your filesystem, username, or other variables.
33
58
34
-
To call a program, we type its name and press enter. Open a terminal and run:
59
+
To call a program, we type its name and press enter. Open a terminal and run:
35
60
36
61
```console
37
62
% ls
38
63
file1 file2
39
64
```
40
65
41
-
Most of the programs which take a file as an input take it as an argument to the command.\
42
-
We list arguments after the command name, separated with a space, e.g. we can pass `/tmp` as an argument to `ls`:
66
+
Most programs that take a file as input accept it as an argument to the command.\
67
+
We list arguments after the command name, separated with a space. For example, we can pass `/tmp` as an argument to `ls`:
43
68
44
69
```console
45
70
% ls /tmp
46
71
some-temporary-file some-other-temporary file
47
72
```
48
73
49
-
#### Flags and arguments
74
+
#### Flags and Arguments
50
75
51
-
Some programs take extra arguments. These may be optional or required. Extra arguments generally start with a `-` or `--`then their name. If these extra arguments take a value, expect the value to come _after_ the name.
76
+
Some programs take extra arguments. These may be optional or required. Extra arguments generally start with a `-` or `--`followed by their name. If these extra arguments take a value, expect the value to come _after_ the name.
52
77
53
78
```console
54
79
% grep -r -B 1 "hello".
@@ -59,10 +84,10 @@ Some programs take extra arguments. These may be optional or required. Extra arg
59
84
./errors/index.md:const result = console.log("hello world");
60
85
```
61
86
62
-
Here we passed the optional argument `-r` and the optional argument `-B`. `-r` takes no value. We gave `-B` the value 1.
87
+
Here we passed the optional argument `-r` and the optional argument `-B`. `-r` takes no value. We gave `-B` the value 1.
63
88
64
-
We call arguments that start with a `-` or `--` flags. We could give flags in any order - `grep -B 1 -r "hello" .` works the same as `grep -r -B 1 "hello" .`.
89
+
We call arguments that start with a `-` or `--`**flags**. We could give flags in any order - `grep -B 1 -r "hello" .` works the same as `grep -r -B 1 "hello" .`.
65
90
66
-
Flags that start with a `-` not a `--` can also be squashed together. `grep -rc "Hello" .` works the same as `grep -r -c "Hello" .`. If you are looking up a flag you don't know, like `-rc`, remember it may actaully be two flags (`-r` and `-c`). You can also specify a value for the _last_ flag in a squashed together list: `grep -rcB 1 "hello" .`.
91
+
Flags that start with a `-`(not `--`) can also be combined together. `grep -rc "Hello" .` works the same as `grep -r -c "Hello" .`. If you are looking up a flag you don't know, like `-rc`, remember it may actually be two flags (`-r` and `-c`). You can also specify a value for the _last_ flag in a combined list: `grep -rcB 1 "hello" .`.
67
92
68
-
`"hello"` and `.` are called positional arguments because they don't have a named flag before them. The program decides how to interpret them based on their position (order) in the command line, rather than a named flag coming before them. Their order matters.
93
+
`"hello"` and `.` are called **positional arguments** because they don't have a named flag before them. The program decides how to interpret them based on their position (order) in the command line, rather than a named flag coming before them. Their order matters.
0 commit comments