Skip to content

Commit dbf5f25

Browse files
author
Lei Wang
committed
Added sample files.
1 parent 1f05f52 commit dbf5f25

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

README.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,34 @@ ls [/path/to/directory]
6969
> ls data/sample
7070
> ls -la data/sample
7171
> ls -lah /workspace/unix/data/sample
72-
> ls -lahr /workspace/unix/data/sample
7372
> ```
7473
7574
![Command](./images/command.jpg)
7675
7776
> [!TIP]
7877
> **Relative path** starts from the present working directory. For example, suppose we are currently in `/workspace/unixclass/data`:
7978
> ```
80-
> my_file.csv # => /workspace/unixclass/data/my_file.csv
81-
> sample/my_file.csv # => /workspace/unixclass/data/sample/my_file.csv
79+
> my_file.txt # => /workspace/unixclass/data/my_file.txt
80+
> sample/my_file.txt # => /workspace/unixclass/data/sample/my_file.txt
8281
> ```
8382
> **Absolute path** starts from the root directory, so it always starts with `/`:
8483
> ```
85-
> /workspace/unixclass/my_file.csv
86-
> /workspace/unixclass/data/my_file.csv
84+
> /workspace/unixclass/my_file.txt
85+
> /workspace/unixclass/data/my_file.txt
8786
> ```
8887
8988
> [!TIP]
9089
> **Special Characters**.
9190
> **Forward slash** `/` denotes the root directory at the beginning of a path, and is the element delimiter in the middle of a path:
9291
> ```
9392
> / # Root directory
94-
> data/my_file.csv # Delimits the directory name "data" from the file name "my_file.csv"
95-
> /workspace/unixclass/data/my_file.csv # The first slash denotes the root directory, and the subsequent ones delimit path elements
93+
> data/my_file.txt # Delimits the directory name "data" from the file name "my_file.txt"
94+
> /workspace/unixclass/data/my_file.txt # The first slash denotes the root directory, and the subsequent ones delimit path elements
9695
> ```
97-
> A **single dot** `.` represents the present working directory, and **double dots** `..` represent the parent directory of the present working directory. Assume we are currently in `/workspace/unixclass/data`:
96+
> A **single dot** `.` represents the present working directory, and **double dots** `..` represent the parent directory of the present working directory. Assume we are currently in `/workspace/unixclass/data/sample`:
9897
> ```
99-
> ./my_file.csv # => my_file.csv => /workspace/unixclass/data/my_file.csv
100-
> ../README.md # => /workspace/unixclass/README.md
98+
> ./my_file.txt # => my_file.txt => /workspace/unixclass/data/sample/my_file.txt
99+
> ../my_file.txt # => /workspace/unixclass/data/my_file.txt
101100
> ```
102101
> Sometimes you may also encounter the **tilde** character `~`, which in most Unix systems denote the user's "home directory".
103102
@@ -141,9 +140,9 @@ cp [/path/to/source] [/path/to/destination]
141140
```
142141
For example:
143142
```
144-
cp data/my_file.csv data/sample_1/my_file.csv
145-
cp data/my_file.csv data/sample_1/
146-
cp data/my_file.csv data/sample_1/my_file_copy.csv # copy to new location with a new name
143+
cp data/my_file.txt data/sample_1/my_file.txt
144+
cp data/my_file.txt data/sample_2/
145+
cp data/my_file.txt data/sample_3/my_file_copy.txt # copy to new location with a new name
147146
```
148147
149148
To **copy a directory** with its contents, use `cp` with the `-R` (recursive) (or sometimes `-r` also works) flag:
@@ -157,14 +156,15 @@ mv [/path/to/source] [/path/to/destination]
157156
```
158157
For example:
159158
```
160-
mv data/my_file.csv data/sample_4/my_file.csv
161-
mv data/my_file.csv data/sample_4/
162-
mv data/my_file.csv data/sample_4/my_file_new.csv # move to new location with a new name
159+
mkdir -p data/sample_5 data/sample_6 data/sample_7
160+
mv data/my_file.txt data/sample_5/my_file.txt
161+
mv data/sample_5/my_file.txt data/sample_6/
162+
mv data/sample_6/my_file.txt data/sample_7/my_file_new.txt # move to new location with a new name
163163
```
164164
When using `mv` in the same location, it is effectively **renaming** the file or directory:
165165
```
166-
mv data/my_file.csv data/my_file_backup.csv
167-
mv data/sample_1 data/sample_5
166+
mv data/sample_5/my_file.txt data/sample_5/my_file_backup.txt
167+
mv data/sample_7 data/sample_8
168168
```
169169
170170
To **remove** files, use:
@@ -173,7 +173,7 @@ rm [/path/to/file]
173173
```
174174
For example:
175175
```
176-
rm data/sample/my_file.csv
176+
rm data/sample_3/my_file.txt
177177
```
178178
To **remove** a directory together with its contents, use `rm` with the `-R` (recursive) (or sometimes `-r` also works) flag:
179179
```
@@ -187,11 +187,11 @@ rm -R data/sample_5
187187
> **Special Characters**.
188188
> The **question mark** `?` is a wildcard character that denotes one character when specifying file names:
189189
> ```
190-
> cp data/sample/my_file_?.csv data/sample_1/ # => my_file_1.csv, my_file_2.csv, ...
190+
> cp data/sample/my_file_?.txt data/sample_1/ # => my_file_1.txt, my_file_2.txt, ...
191191
> ```
192192
> The **asterisk** `*` is a wildcard character that denotes any number of characters when specifying file names:
193193
> ```
194-
> cp data/sample/*.csv data/sample_1/ # => my_file.csv, another_file.csv, yet_another_file.csv, ...
194+
> cp data/sample/*.txt data/sample_1/ # => my_file.txt, another_file.txt, yet_another_file.txt, ...
195195
> ```
196196
197197
<br/>
@@ -306,9 +306,10 @@ tail covid.txt
306306
> ```
307307
> head -n 100 covid.csv # display the first 100 lines
308308
> tail -n 50 covid.csv # display the last 50 lines
309+
> tail -n +2 covid.csv # display all lines except the first line
309310
> ```
310311
311-
If the file is large, and you want to search its content, `grep` is a very powerful tool. For example:
312+
If the file is large, and you want to **search** its content, `grep` is a very powerful tool. For example:
312313
```
313314
grep 'sweet' shakespeare.txt # find all instances of the word 'sweet'
314315
grep –i 'sweet' shakespeare.txt # same as above but case-insensitive
@@ -419,7 +420,7 @@ COUNTER=0
419420
for datafile in covid*.csv
420421
do
421422
echo "Adding $datafile …"
422-
tail -n +2 $datafile >> combined-covid.csv
423+
tail -n +2 $datafile | sort -r | cut -d , -f 2,3,4,5 >> combined-covid.csv
423424
COUNTER=$((COUNTER + 1))
424425
done
425426

data/my_file.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hi from my_file.txt under data!

data/sample/my_file.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hi from my_file.txt under data/sample!

0 commit comments

Comments
 (0)