forked from levylorenzo/mtec1003_lab_03_commandline_03
/
lab-03-part-02-work-with-files.txt
223 lines (150 loc) · 5.32 KB
/
lab-03-part-02-work-with-files.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
Lab - Working With Files
==========
Follow the instructions line-by-line.
* Type in the commands as is, but ignore the beginning prompt.
* Enter, tab, up and down are represented by <ENTER><TAB>,<UP> and <DOWN>.
* "No output" or "nothing happens" are valid answers to any of the questions.
==========
==========
1. Open a new terminal window.
[NO OUTPUT]
----------
==========
2. Find out if mtec1003-lab-03 already exists (from the previous lab). If it doesn't, go back to the previous lab and find the steps regarding downloading the lab materials.
(See steps 1-8 in http://entertainmenttechnology.github.io/Wilson-MTEC1003/labs/03/lab-03-part-01-review.txt)
[NO OUTPUT]
----------
==========
3. Change your directory mtec1003-lab-03
[NO OUTPUT]
----------
==========
4. Create a directory called my_files
[NO OUTPUT]
----------
==========
5. Change the directory to my_files
[NO OUTPUT]
----------
==========
6. Create a new file using touch.
$ touch foo.txt
$ ls
Copy and paste the output below.
----------
foo.txt
==========
7. Create another new file using touch.
$ touch bar.txt
----------
==========
8. List the files in this directory using the flag that gives the most details.
Copy and paste the output below.
----------
total 0
drwxr-xr-x 4 student staff 136 Feb 20 15:52 .
-rw-r--r-- 1 student staff 0 Feb 20 15:52 bar.txt
-rw-r--r-- 1 student staff 0 Feb 20 15:51 foo.txt
drwxr-xr-x 8 student staff 272 Feb 20 15:51 ..
==========
9. Create a copy of bar.txt called baz.txt and then list the files again.
Write the command that you used to copy the file. Additionally, copy and paste the output of your file listing below.
----------
cp bar.txt baz.txt
bar.txt baz.txt foo.txt
==========
10. Delete the file called bar.txt and then list the files again.
Write the command that you used to remove the file. Copy and paste the output of your file listing below.
----------
rm bar.txt
baz.txt foo.txt
==========
11. Move the file called foo.txt to qux.txt and then list the files again.
Write the command that you used to move the file. Copy and paste the output of your file listing below.
----------
mv foo.txt qux.txt
baz.txt qux.txt
==========
12. Go up one directory so that you're in ~/mtec1003-lab-03.
[NO OUTPUT]
----------
cd ..
==========
13. Try removing the directory called my_files using rmdir.
Write out the command that you used and what happened.
----------
rmdir my_files/
rmdir: my_files/: Directory not empty
==========
14. Try removing the directory called my_files using rm.
Write out the command that you used and what happened.
----------
rm my_files/
rm: my_files/: is a directory
==========
15. MAKE SURE YOU'RE IN THE mtec1003-lab-03 directory!
Force the removal of the directory and files using the -rf flag
$ rm -rf my_files
----------
ls
books logs logs.tar.gz web
==========
16. There's a txt file version of a book located in the mtec1003-lab-03 folder. It is in the following directory if you're in the lab folder:
books/other/pg1232.txt
Use the command called cat on the file to show its contents.
Describe what happened below.
----------
cd books/other
cat pg1232.txt
Displays entire text of eBook: The Prince, by Nicolo Machiavelli
==========
17. That was a lot of text. Let's find ways to limit it. Using the same file...
books/other/pg1232.txt
Use the command, head, on the file to show the contents of the beginning of the file.
Write the command that you used below. Write the last line of the output below (it should be the title).
----------
head pg1232.txt
Title: The Prince
==========
18. Using the same file again!
books/other/pg1232.txt
Use tail on the file to show the contents of the end of the file.
Write the command that you used below. Write the last line of the output below.
----------
tail pg1232.txt
This Web site includes information about Project Gutenberg-tm,
including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how to
subscribe to our email newsletter to hear about new eBooks.
==========
19. Using the same file...
books/other/pg1232.txt
Use less and more on the file to show the contents of the file. Try pressing spacebar and/or q afterwards.
Write the command that you used below. Describe what spacebar and q does after using either less or more.
----------
spacebar jumps sections
q brings you back to the end of the text file.
==========
20. Describe what situations you would use the following commands for viewing files: less, more, cat, tail, head
(Some characteristics that may help your description might be the length of the file, whether or not you'd like to read the whole thing... or just the beginning or end, etc.)
----------
less: shows less text
more: shows more text
cat: shows all text of the file
tail: jumps to end
head: jumps to front
==========
21. How many words are in pg1232.txt? What command did you use to determine the word count?
----------
52639 words
wc pg1232.txt
==========
22. How many lines are in pg1232.txt? What command did you use to determine the line count?
----------
wc -l pg1232.txt
5063 pg1232.txt
==========
23. Make sure you're in the books/other folder. Copy all of the txt files from that folder to your home directory using wildcard matching.
Write the command that you used below.
----------
mv *.txt /Users/student/