Skip to content

Commit b32bd63

Browse files
committed
more
1 parent 8e3484b commit b32bd63

File tree

1 file changed

+94
-9
lines changed

1 file changed

+94
-9
lines changed

04-linux-101 copy.md

+94-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Getting Started with Raspberry Pi
99

1010
# Learn a little Linux
1111

12+
The purpose of this is to present basic terminal commands that will be used during CODE@TACC.
13+
1214
## Navigating the filesystem
1315

1416
The part of the operating system responsible for managing files
@@ -25,7 +27,7 @@ and delete files and directories.
2527
To start exploring them, let's open a terminal window:
2628

2729
```
28-
$
30+
$
2931
```
3032

3133
The dollar sign is a prompt, which shows us that the shell is waiting for input.
@@ -111,19 +113,19 @@ $ pwd
111113
Another option when changing directories is to list the complete *absolute* path starting with root directory `/`
112114

113115
```
114-
$ cd /users/look_up_what_is_there_by_default
116+
$ cd /home/pi/Desktop
115117
```
116118

117119
If you type `cd` by itself, you will go into your home directory
118120
#### Challenge
119121

120-
1. Find the path of your home directory
122+
1. Discover the path of your home directory
121123

122124
#### What you learned
123125

124126
1. How to find what directory you are in using `pwd`
125127
2. Using `ls -F` to list files in your current working directory
126-
3. Changing directories using `cd <directory_name>`
128+
3. Changing directories
127129
4. How to get to your home directory
128130

129131
#### More info
@@ -133,22 +135,105 @@ If you type `cd` by itself, you will go into your home directory
133135

134136
## Creating and deleting files and directories
135137

136-
https://github.com/johnfonner/TACCLinuxBasics/blob/master/shell/02-create.md
138+
We now know how to explore directories and files, but how do we create new ones?
139+
140+
Go ahead and create a new directory called `my_scripts` using the command `mkdir my_scripts`.
141+
142+
```
143+
$ cd
144+
$ mkdir my_scripts
145+
```
146+
147+
As you might (or might not) guess from its name, `mkdir` means *make directory*.
148+
Since `my_scripts` is a relative path (i.e., doesn't have a leading slash),
149+
the new directory is made below the current working directory:
150+
151+
```
152+
$ ls -F
153+
```
154+
155+
However, there's nothing in it yet:
156+
157+
```
158+
$ cd my_scripts
159+
$ ls -F
160+
```
161+
162+
To create an empty file, you can use the command `touch`.
163+
164+
```
165+
$ touch draft.txt
166+
$ ls -F
167+
```
168+
169+
At this point, you want to make a backup of this *very* important empty file. You can use `cp` to make copies of files or directories
137170

138-
mkdirnano (or Leafpad)mvcprmrmdir
171+
```
172+
$ cp draft.txt draft2.txt
173+
$ ls -F
174+
```
175+
176+
You can see that the command `cp` took two filenames. The first one was the existing file, the second was the new file.
177+
178+
If you decide that *draft2.txt* is not the best name for a backup file, you can change a name using the `mv` command which moves the file.
179+
180+
```
181+
$ mv draft2.txt draft_backup.txt
182+
$ ls -F
183+
```
184+
185+
As *move* implies, it can be used to actually move the file someplace else. For example, if we do not want the backup file in this directory, we can move it out.
186+
187+
```
188+
$ mv draft_backup.txt ../draft_backup.txt
189+
$ ls -F
190+
```
191+
192+
Based on what you know from `cp`, can you see how `mv` works? Where is the draft_backup.txt file now? Can you find it?
193+
194+
```
195+
$ cd ..
196+
$ ls -F
197+
```
198+
199+
Okay, now that we have made a mess with empty files and directories we do not actually need, let’s clean up.
200+
201+
***Notice!*** Deleting Is Forever
202+
203+
```
204+
$ rm draft_backup.txt
205+
$ ls -F
206+
```
207+
208+
`rm` is short for "remove”. It works on files, but not directories. For directories, you can use `rmdir`.
209+
210+
For safety purposes, `rmdir` only works on empty directories. Because we left a file in the folder *my_scripts*, the following command will not work.
211+
212+
```
213+
$ rmdir my_scripts
214+
```
215+
216+
To override this, you can use `rm -r`. Please be careful with this command, and only use it on directories that you are certain have nothing you wish to keep.
217+
218+
```
219+
$ rm -r my_scripts
220+
$ ls -F
221+
```
222+
223+
The `-r` in this case indicates that the command is *recursive*, which means it will delete all files and subdirectories and their files and subdirectories and so on and so on. As you can imagine, this could be a lot of files.
139224

140225
#### Challenges
141226

142-
1. Don’t erase your filesystem!
227+
1. Don’t erase your entire filesystem!
143228

144229
#### What you learned
145230

146231
1. Making a new directory with `mkdir`
147-
2. Creating a file
232+
2. Creating an empty file with `touch`
148233
3. Changing the name and/or location of a file or directory with `mv`
149234
4. Duplicating a file or directory with `cp`
150235
5. Removing a file or directory with `rm` or `rmdir` respectively
151-
236+
6. Be careful when using `rm -r`
152237

153238
#### More info
154239

0 commit comments

Comments
 (0)