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: lessons/lesson02.md
+35-89Lines changed: 35 additions & 89 deletions
Original file line number
Diff line number
Diff line change
@@ -1,37 +1,55 @@
1
-
## Lesson 02 - Command Line and Bash
1
+
## Lesson 02 - Command Line Part I
2
2
3
3
Skills you will learn in this lesson:
4
4
5
-
* Moving between directories and creating/removing files
6
-
* Working with commands and processes
5
+
* Moving between directories
6
+
* Absolute and relative paths
7
+
* Creating, moving, and removing files and directories
7
8
* Investigating text files
8
-
* Parsing files
9
-
* Working with input and output
10
-
* Absolute and relative paths, symbolic links
11
-
* Bash variables and commands
12
-
* Text editors: nano, vim, emacs, Atom, Sublime Text, MacDown
13
-
* Executing bash scripts and dot-files (e.g., `.bash_profile`)
14
-
* Setting up your Terminal settings and bash environment
9
+
* Working with commands and processes
10
+
* GUI and command-line text editors
11
+
* Setting up your bash environment
15
12
16
13
### Basic commands
17
14
18
-
#### Moving between directories and creating/removing files
15
+
#### Moving between directories
19
16
20
17
*`pwd` -- print working directory
21
18
*`ls` -- list contents of working directory
22
19
*`cd DIRECTORY` -- change to directory
23
20
*`cd` -- change to home directory
24
21
*`cd -` -- change to previous directory
22
+
23
+
#### Absolute and relative paths
24
+
25
+
*`.` -- current directory
26
+
*`..` -- one directory up
27
+
*`../..` -- two directories up
28
+
*`/` -- root directory
29
+
*`~` -- home directory
30
+
31
+
#### Creating, moving, and removing files and directories
32
+
25
33
*`mkdir DIRECTORY` -- make directory
26
34
*`rmdir DIRECTORY` -- remove empty directory
27
-
*`touch FILE` -- create an empty file
35
+
*`touch FILE` -- create an empty file or change file modification time
28
36
*`cat FILE` -- print contents of file
29
37
*`cat > FILE` -- write to file
30
38
*`cat >> FILE` -- append to file
31
39
*`cp FILE1 FILE2` -- copy file
32
40
*`mv FILE1 FILE2` -- move file
33
41
*`rm FILE` -- remove file
34
-
*`exit` -- close the current session
42
+
*`ln -s FILE LINK` -- make a symbolic link
43
+
44
+
#### Investigating text files
45
+
46
+
*`less FILE` -- view a text file
47
+
*`head FILE` -- first 10 lines of file
48
+
*`tail FILE` -- last 10 lines of file
49
+
*`wc FILE` -- count the words and characters in a file
50
+
*`open FILE` -- open a file using default program (on a Mac)
51
+
*`file FILE` -- get the file type for file(s)
52
+
*`grep REGEX FILE` -- search a text file for a string or regular expression
35
53
36
54
#### Working with commands and processes
37
55
@@ -40,6 +58,7 @@ Skills you will learn in this lesson:
40
58
*`which COMMAND` -- show location of command
41
59
*`history` -- display past commands
42
60
*`top` -- display current processes
61
+
*`exit` -- close the current session
43
62
44
63
### Text editors
45
64
@@ -53,9 +72,9 @@ A great way to document your work is using Markdown, a simple markup style. It i
53
72
54
73
For small jobs or if you want to stay inside the terminal, there are other useful programs. Note: `cat` is only useful for creating very basic files, or starting files and finishing them in a proper text editor.
55
74
56
-
*`nano FILE` - nano is the most basic text editor (see Appendix: The Nano Text Editor at end of this lesson)
57
-
*`emacs FILE` - emacs is a popular full-featured text editor controlled by keystrokes
58
-
*`vim FILE` - vim or vi is a popular competitor to emacs that loads faster
75
+
*`nano FILE` -- nano is the most basic text editor (see Appendix: The Nano Text Editor at end of this lesson)
76
+
*`emacs FILE` -- emacs is a popular full-featured text editor controlled by keystrokes
77
+
*`vim FILE` -- vim or vi is a popular competitor to emacs that loads faster
59
78
60
79
### Setting up your bash environment
61
80
@@ -92,79 +111,6 @@ alias rm='rm -i'
92
111
alias taill='ls -lrt | tail'
93
112
```
94
113
95
-
### More commands
96
-
97
-
#### Investigating text files
98
-
99
-
*`less FILE` -- view a text file
100
-
*`head FILE` -- first 10 lines of file
101
-
*`tail FILE` -- last 10 lines of file
102
-
*`wc FILE` -- count the words and characters in a file
103
-
*`open FILE` -- open a file using default program (on a Mac)
104
-
*`file FILE` -- get the file type for file(s)
105
-
*`grep REGEX FILE` -- search a text file for a string or regular expression
106
-
107
-
#### Parsing files
108
-
109
-
*`cut -d "," -f 5- FILE` -- output 5th field through end using comma field delimiter
110
-
*`sed 's/FIND/REPLACE/g'` -- replace text in a file
111
-
*`perl --e 's/FIND/REPLACE/g'` -- run perl commands in the command line (advanced)
112
-
113
-
#### Working with input and output
114
-
115
-
*`|` -- pipe output from one command to another
116
-
*`>` -- redirect (write) to file
117
-
*`<` -- get output of file (other type of redirect)
118
-
*`` `COMMAND` `` -- pass output of a command (e.g., in a for loop)
119
-
120
-
#### Absolute and relative paths, symbolic links
121
-
122
-
*`.` -- current directory
123
-
*`..` -- one directory up
124
-
*`../..` -- two directories up
125
-
*`/` -- root directory
126
-
*`~` -- home directory
127
-
*`ln -s FILE LINK` -- make a symbolic link
128
-
129
-
#### Wildcards
130
-
131
-
*`?` - match any single character
132
-
*`*` - match any string of characters
133
-
*`[set]` - match any character in set
134
-
*`[!set]` - match any character *not* in set
135
-
136
-
#### Brace expansion
137
-
138
-
*`{start..end}` - expand a range; e.g., `b{ed,olt,ar}s`, `{2..5}`, `{d..h}`
139
-
140
-
#### Control keys
141
-
142
-
*`CTRL-C` - stop current command
143
-
*`CTRL-D` - end of input
144
-
*`CTRL-Z` - suspend current command
145
-
146
-
### Variables, bash scripts, and dot-files
147
-
148
-
#### Bash variables and commands
149
-
150
-
*`A=0` -- assign a variable
151
-
*`echo VARIABLE` -- output the value of a variable or expression
152
-
*`$PATH` -- your path variable
153
-
*`$SHELL` -- your current shell
154
-
*`$RANDOM` -- a random number
155
-
*`$PPID` -- process ID
156
-
*`$HOME` -- your home directory (another name for `~` or `/Users/you`)
157
-
*`for VARIABLE in LIST; do COMMANDS; done` -- `for` loop in bash
158
-
159
-
#### Commands
160
-
161
-
*`bash SCRIPT.sh` -- run a bash shell script
162
-
*`source .DOTFILE` -- run a dot-file like your .bash_profile
163
-
164
-
#### Bash scripts
165
-
166
-
Any of the commands we have used from the command line (the bash prompt `$`) can also be typed into a text file and executed by typing `bash SCRIPT.sh` from the command line.
167
-
168
114
### Appendix: The Nano Text Editor
169
115
170
116
Credit: [SDSU Department of Astronomy](http://mintaka.sdsu.edu/reu/nano.html)
*`cut -d "," -f 5- FILE` -- output 5th field through end using comma field delimiter
18
+
*`sed 's/FIND/REPLACE/g'` -- replace text in a file
19
+
*`perl --e 's/FIND/REPLACE/g'` -- run perl commands in the command line (advanced)
20
+
21
+
#### Working with input and output
22
+
23
+
*`|` -- pipe output from one command to another
24
+
*`>` -- redirect (write) to file
25
+
*`<` -- get output of file (other type of redirect)
26
+
*`` `COMMAND` `` -- pass output of a command (e.g., in a for loop)
27
+
28
+
#### Wildcards
29
+
30
+
*`?` -- match any single character
31
+
*`*` -- match any string of characters
32
+
*`[set]` -- match any character in set
33
+
*`[!set]` -- match any character *not* in set
34
+
35
+
#### Brace expansion
36
+
37
+
*`{start..end}` -- expand a range; e.g., `b{ed,olt,ar}s`, `{2..5}`, `{d..h}`
38
+
39
+
#### Control keys
40
+
41
+
*`CTRL-C` -- stop current command
42
+
*`CTRL-D` -- end of input
43
+
*`CTRL-Z` -- suspend current command
44
+
45
+
### Variables, bash scripts, and dot-files
46
+
47
+
#### Bash variables and commands
48
+
49
+
*`A=0` -- assign a variable
50
+
*`echo VARIABLE` -- output the value of a variable or expression
51
+
*`$PATH` -- your path variable
52
+
*`$SHELL` -- your current shell
53
+
*`$RANDOM` -- a random number
54
+
*`$PPID` -- process ID
55
+
*`$HOME` -- your home directory (another name for `~` or `/Users/you`)
56
+
*`for VARIABLE in LIST; do COMMANDS; done` -- `for` loop in bash
57
+
58
+
#### Executing bash scripts and dot-files
59
+
60
+
*`bash SCRIPT.sh` -- run a bash shell script
61
+
*`source .DOTFILE` -- run a dot-file like your .bash_profile
62
+
63
+
Any of the commands we have used from the command line (the bash prompt `$`) can also be typed into a text file and executed by typing `bash SCRIPT.sh` from the command line.
0 commit comments